NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

debug-utils.php 885B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. // Tools for testing and debugging P2P
  3. add_action( 'p2p_registered_connection_type', '_p2p_register_missing_post_types' );
  4. function _p2p_register_missing_post_types( $ctype ) {
  5. foreach ( _p2p_extract_post_types( $ctype->side ) as $ptype ) {
  6. if ( !post_type_exists( $ptype ) ) {
  7. _p2p_generate_post_type( $ptype );
  8. }
  9. }
  10. }
  11. function _p2p_generate_post_type( $slug ) {
  12. register_post_type( $slug, array(
  13. 'labels' => array(
  14. 'name' => ucfirst( $slug ),
  15. 'singular_name' => ucfirst( $slug ),
  16. ),
  17. 'public' => true,
  18. 'supports' => array( 'title' )
  19. ) );
  20. }
  21. function _p2p_walk( $posts, $level = 0 ) {
  22. if ( 0 == $level )
  23. echo "<pre>\n";
  24. foreach ( $posts as $post ) {
  25. echo str_repeat( "\t", $level ) . "$post->ID: $post->post_title\n";
  26. if ( isset( $post->connected ) )
  27. _p2p_walk( $post->connected, $level+1 );
  28. }
  29. if ( 0 == $level )
  30. echo "</pre>\n";
  31. }