Guest User

http://wordpress.stackexchange.com/questions/221485/

a guest
Mar 30th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.24 KB | None | 0 0
  1. <?php
  2.  
  3. // This is page.php
  4.  
  5. global $post;
  6.  
  7. $post_id = $post->ID;
  8. $parent = $post->post_parent > 0 ? $post->post_parent : $post_id;
  9.  
  10. $q = new WP_Query(array(
  11.     'wpse_include_parent' => true,
  12.     'post_parent' => $parent,
  13.     'post_type'  => 'page',
  14.     'post_status' => 'publish',
  15.     'orderby' => 'menu_order',
  16.     'order' => 'ASC',
  17. ));
  18.  
  19. var_dump($q);
  20.  
  21. /*
  22.  
  23. ## Output of the var dump
  24.  
  25. object(WP_Query)#1625 (52) {
  26.   ["query"]=>
  27.   array(6) {
  28.     ["wpse_include_parent"]=>
  29.     bool(true)
  30.     ["post_parent"]=>
  31.     int(2116)
  32.     ["post_type"]=>
  33.     string(4) "page"
  34.     ["post_status"]=>
  35.     string(7) "publish"
  36.     ["orderby"]=>
  37.     string(10) "menu_order"
  38.     ["order"]=>
  39.     string(3) "ASC"
  40.   }
  41.   ["query_vars"]=>
  42.   array(66) {
  43.     ["wpse_include_parent"]=>
  44.     bool(true)
  45.     ["post_parent"]=>
  46.     int(2116)
  47.     ["post_type"]=>
  48.     string(4) "page"
  49.     ["post_status"]=>
  50.     string(7) "publish"
  51.     ["orderby"]=>
  52.     string(10) "menu_order"
  53.     ["order"]=>
  54.     string(3) "ASC"
  55.     ["error"]=>
  56.     string(0) ""
  57.     ["m"]=>
  58.     string(0) ""
  59.     ["p"]=>
  60.     int(0)
  61.     ["subpost"]=>
  62.     string(0) ""
  63.     ["subpost_id"]=>
  64.     string(0) ""
  65.     ["attachment"]=>
  66.     string(0) ""
  67.     ["attachment_id"]=>
  68.     int(0)
  69.     ["name"]=>
  70.     string(0) ""
  71.     ["static"]=>
  72.     string(0) ""
  73.     ["pagename"]=>
  74.     string(0) ""
  75.     ["page_id"]=>
  76.     int(0)
  77.     ["second"]=>
  78.     string(0) ""
  79.     ["minute"]=>
  80.     string(0) ""
  81.     ["hour"]=>
  82.     string(0) ""
  83.     ["day"]=>
  84.     int(0)
  85.     ["monthnum"]=>
  86.     int(0)
  87.     ["year"]=>
  88.     int(0)
  89.     ["w"]=>
  90.     int(0)
  91.     ["category_name"]=>
  92.     string(0) ""
  93.     ["tag"]=>
  94.     string(0) ""
  95.     ["cat"]=>
  96.     string(0) ""
  97.     ["tag_id"]=>
  98.     string(0) ""
  99.     ["author"]=>
  100.     string(0) ""
  101.     ["author_name"]=>
  102.     string(0) ""
  103.     ["feed"]=>
  104.     string(0) ""
  105.     ["tb"]=>
  106.     string(0) ""
  107.     ["paged"]=>
  108.     int(0)
  109.     ["comments_popup"]=>
  110.     string(0) ""
  111.     ["meta_key"]=>
  112.     string(0) ""
  113.     ["meta_value"]=>
  114.     string(0) ""
  115.     ["preview"]=>
  116.     string(0) ""
  117.     ["s"]=>
  118.     string(0) ""
  119.     ["sentence"]=>
  120.     string(0) ""
  121.     ["title"]=>
  122.     string(0) ""
  123.     ["fields"]=>
  124.     string(0) ""
  125.     ["menu_order"]=>
  126.     string(0) ""
  127.     ["category__in"]=>
  128.     array(0) {
  129.     }
  130.     ["category__not_in"]=>
  131.     array(0) {
  132.     }
  133.     ["category__and"]=>
  134.     array(0) {
  135.     }
  136.     ["post__in"]=>
  137.     array(0) {
  138.     }
  139.     ["post__not_in"]=>
  140.     array(0) {
  141.     }
  142.     ["post_name__in"]=>
  143.     array(0) {
  144.     }
  145.     ["tag__in"]=>
  146.     array(0) {
  147.     }
  148.     ["tag__not_in"]=>
  149.     array(0) {
  150.     }
  151.     ["tag__and"]=>
  152.     array(0) {
  153.     }
  154.     ["tag_slug__in"]=>
  155.     array(0) {
  156.     }
  157.     ["tag_slug__and"]=>
  158.     array(0) {
  159.     }
  160.     ["post_parent__in"]=>
  161.     array(0) {
  162.     }
  163.     ["post_parent__not_in"]=>
  164.     array(0) {
  165.     }
  166.     ["author__in"]=>
  167.     array(0) {
  168.     }
  169.     ["author__not_in"]=>
  170.     array(0) {
  171.     }
  172.     ["ignore_sticky_posts"]=>
  173.     bool(false)
  174.     ["suppress_filters"]=>
  175.     bool(false)
  176.     ["cache_results"]=>
  177.     bool(true)
  178.     ["update_post_term_cache"]=>
  179.     bool(true)
  180.     ["update_post_meta_cache"]=>
  181.     bool(true)
  182.     ["posts_per_page"]=>
  183.     int(10)
  184.     ["nopaging"]=>
  185.     bool(false)
  186.     ["comments_per_page"]=>
  187.     string(2) "50"
  188.     ["no_found_rows"]=>
  189.     bool(false)
  190.   }
  191.   ["tax_query"]=>
  192.   object(WP_Tax_Query)#1665 (6) {
  193.     ["queries"]=>
  194.     array(0) {
  195.     }
  196.     ["relation"]=>
  197.     string(3) "AND"
  198.     ["table_aliases":protected]=>
  199.     array(0) {
  200.     }
  201.     ["queried_terms"]=>
  202.     array(0) {
  203.     }
  204.     ["primary_table"]=>
  205.     string(10) "a7Wq_posts"
  206.     ["primary_id_column"]=>
  207.     string(2) "ID"
  208.   }
  209.   ["meta_query"]=>
  210.   object(WP_Meta_Query)#1723 (9) {
  211.     ["queries"]=>
  212.     array(0) {
  213.     }
  214.     ["relation"]=>
  215.     NULL
  216.     ["meta_table"]=>
  217.     NULL
  218.     ["meta_id_column"]=>
  219.     NULL
  220.     ["primary_table"]=>
  221.     NULL
  222.     ["primary_id_column"]=>
  223.     NULL
  224.     ["table_aliases":protected]=>
  225.     array(0) {
  226.     }
  227.     ["clauses":protected]=>
  228.     array(0) {
  229.     }
  230.     ["has_or_relation":protected]=>
  231.     bool(false)
  232.   }
  233.   ["date_query"]=>
  234.   bool(false)
  235.   ["request"]=>
  236.   string(534) "SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  JOIN wp_icl_translations t
  237.                             ON wp_posts.ID = t.element_id
  238.                                 AND t.element_type = CONCAT('post_', wp_posts.post_type)  WHERE 1=1  AND wp_posts.post_parent = 2116  AND wp_posts.post_type = 'page' AND ((wp_posts.post_status = 'publish')) AND ( ( t.language_code = 'en' AND wp_posts.post_type  IN ('post','page','acf' )  ) OR wp_posts.post_type  NOT  IN ('post','page','acf' )  ) OR wp_posts.ID = 2116  ORDER BY wp_posts.menu_order ASC LIMIT 0, 10"
  239.   ["posts"]=>
  240.   array(2) {
  241.     [0]=>
  242.     object(WP_Post)#1626 (24) {
  243.       ["ID"]=>
  244.       int(2116)
  245.       ["post_author"]=>
  246.       string(1) "1"
  247.       ["post_date"]=>
  248.       string(19) "2016-03-21 17:24:55"
  249.       ["post_date_gmt"]=>
  250.       string(19) "2016-03-21 15:24:55"
  251.       ["post_content"]=>
  252.       string(711) "Parent Content"
  253.       ["post_title"]=>
  254.       string(26) "Parent Post"
  255.       ["post_excerpt"]=>
  256.       string(0) ""
  257.       ["post_status"]=>
  258.       string(7) "publish"
  259.       ["comment_status"]=>
  260.       string(6) "closed"
  261.       ["ping_status"]=>
  262.       string(6) "closed"
  263.       ["post_password"]=>
  264.       string(0) ""
  265.       ["post_name"]=>
  266.       string(26) "parent-post"
  267.       ["to_ping"]=>
  268.       string(0) ""
  269.       ["pinged"]=>
  270.       string(0) ""
  271.       ["post_modified"]=>
  272.       string(19) "2016-03-23 18:59:29"
  273.       ["post_modified_gmt"]=>
  274.       string(19) "2016-03-23 16:59:29"
  275.       ["post_content_filtered"]=>
  276.       string(0) ""
  277.       ["post_parent"]=>
  278.       int(0)
  279.       ["guid"]=>
  280.       string(44) "http://localhost/?page_id=2116"
  281.       ["menu_order"]=>
  282.       int(11)
  283.       ["post_type"]=>
  284.       string(4) "page"
  285.       ["post_mime_type"]=>
  286.       string(0) ""
  287.       ["comment_count"]=>
  288.       string(1) "0"
  289.       ["filter"]=>
  290.       string(3) "raw"
  291.     }
  292.     [1]=>
  293.     object(WP_Post)#1662 (24) {
  294.       ["ID"]=>
  295.       int(2126)
  296.       ["post_author"]=>
  297.       string(1) "1"
  298.       ["post_date"]=>
  299.       string(19) "2016-03-23 11:22:54"
  300.       ["post_date_gmt"]=>
  301.       string(19) "2016-03-23 09:22:54"
  302.       ["post_content"]=>
  303.       string(10) "Child Content"
  304.       ["post_title"]=>
  305.       string(11) "Child Post"
  306.       ["post_excerpt"]=>
  307.       string(0) ""
  308.       ["post_status"]=>
  309.       string(7) "publish"
  310.       ["comment_status"]=>
  311.       string(6) "closed"
  312.       ["ping_status"]=>
  313.       string(6) "closed"
  314.       ["post_password"]=>
  315.       string(0) ""
  316.       ["post_name"]=>
  317.       string(11) "child-post"
  318.       ["to_ping"]=>
  319.       string(0) ""
  320.       ["pinged"]=>
  321.       string(0) ""
  322.       ["post_modified"]=>
  323.       string(19) "2016-03-23 19:01:34"
  324.       ["post_modified_gmt"]=>
  325.       string(19) "2016-03-23 17:01:34"
  326.       ["post_content_filtered"]=>
  327.       string(0) ""
  328.       ["post_parent"]=>
  329.       int(2116)
  330.       ["guid"]=>
  331.       string(44) "http://localhost/?page_id=2126"
  332.       ["menu_order"]=>
  333.       int(111)
  334.       ["post_type"]=>
  335.       string(4) "page"
  336.       ["post_mime_type"]=>
  337.       string(0) ""
  338.       ["comment_count"]=>
  339.       string(1) "0"
  340.       ["filter"]=>
  341.       string(3) "raw"
  342.     }
  343.   }
  344.   ["post_count"]=>
  345.   int(2)
  346.   ["current_post"]=>
  347.   int(-1)
  348.   ["in_the_loop"]=>
  349.   bool(false)
  350.   ["post"]=>
  351.   object(WP_Post)#1626 (24) {
  352.     ["ID"]=>
  353.     int(2116)
  354.     ["post_author"]=>
  355.     string(1) "1"
  356.     ["post_date"]=>
  357.     string(19) "2016-03-21 17:24:55"
  358.     ["post_date_gmt"]=>
  359.     string(19) "2016-03-21 15:24:55"
  360.     ["post_content"]=>
  361.     string(711) "Parent Content"
  362.     ["post_title"]=>
  363.     string(26) "Parent Post"
  364.     ["post_excerpt"]=>
  365.     string(0) ""
  366.     ["post_status"]=>
  367.     string(7) "publish"
  368.     ["comment_status"]=>
  369.     string(6) "closed"
  370.     ["ping_status"]=>
  371.     string(6) "closed"
  372.     ["post_password"]=>
  373.     string(0) ""
  374.     ["post_name"]=>
  375.     string(26) "parent-page"
  376.     ["to_ping"]=>
  377.     string(0) ""
  378.     ["pinged"]=>
  379.     string(0) ""
  380.     ["post_modified"]=>
  381.     string(19) "2016-03-23 18:59:29"
  382.     ["post_modified_gmt"]=>
  383.     string(19) "2016-03-23 16:59:29"
  384.     ["post_content_filtered"]=>
  385.     string(0) ""
  386.     ["post_parent"]=>
  387.     int(0)
  388.     ["guid"]=>
  389.     string(44) "http://localhost/?page_id=2116"
  390.     ["menu_order"]=>
  391.     int(11)
  392.     ["post_type"]=>
  393.     string(4) "page"
  394.     ["post_mime_type"]=>
  395.     string(0) ""
  396.     ["comment_count"]=>
  397.     string(1) "0"
  398.     ["filter"]=>
  399.     string(3) "raw"
  400.   }
  401.   ["comment_count"]=>
  402.   int(0)
  403.   ["current_comment"]=>
  404.   int(-1)
  405.   ["found_posts"]=>
  406.   string(1) "2"
  407.   ["max_num_pages"]=>
  408.   float(1)
  409.   ["max_num_comment_pages"]=>
  410.   int(0)
  411.   ["is_single"]=>
  412.   bool(false)
  413.   ["is_preview"]=>
  414.   bool(false)
  415.   ["is_page"]=>
  416.   bool(false)
  417.   ["is_archive"]=>
  418.   bool(false)
  419.   ["is_date"]=>
  420.   bool(false)
  421.   ["is_year"]=>
  422.   bool(false)
  423.   ["is_month"]=>
  424.   bool(false)
  425.   ["is_day"]=>
  426.   bool(false)
  427.   ["is_time"]=>
  428.   bool(false)
  429.   ["is_author"]=>
  430.   bool(false)
  431.   ["is_category"]=>
  432.   bool(false)
  433.   ["is_tag"]=>
  434.   bool(false)
  435.   ["is_tax"]=>
  436.   bool(false)
  437.   ["is_search"]=>
  438.   bool(false)
  439.   ["is_feed"]=>
  440.   bool(false)
  441.   ["is_comment_feed"]=>
  442.   bool(false)
  443.   ["is_trackback"]=>
  444.   bool(false)
  445.   ["is_home"]=>
  446.   bool(true)
  447.   ["is_404"]=>
  448.   bool(false)
  449.   ["is_embed"]=>
  450.   bool(false)
  451.   ["is_comments_popup"]=>
  452.   bool(false)
  453.   ["is_paged"]=>
  454.   bool(false)
  455.   ["is_admin"]=>
  456.   bool(false)
  457.   ["is_attachment"]=>
  458.   bool(false)
  459.   ["is_singular"]=>
  460.   bool(false)
  461.   ["is_robots"]=>
  462.   bool(false)
  463.   ["is_posts_page"]=>
  464.   bool(false)
  465.   ["is_post_type_archive"]=>
  466.   bool(false)
  467.   ["query_vars_hash":"WP_Query":private]=>
  468.   string(32) "e80c2264d067097729dc5970634346b0"
  469.   ["query_vars_changed":"WP_Query":private]=>
  470.   bool(false)
  471.   ["thumbnails_cached"]=>
  472.   bool(false)
  473.   ["updated_term_meta_cache"]=>
  474.   bool(false)
  475.   ["updated_comment_meta_cache"]=>
  476.   bool(false)
  477.   ["stopwords":"WP_Query":private]=>
  478.   NULL
  479.   ["compat_fields":"WP_Query":private]=>
  480.   array(2) {
  481.     [0]=>
  482.     string(15) "query_vars_hash"
  483.     [1]=>
  484.     string(18) "query_vars_changed"
  485.   }
  486.   ["compat_methods":"WP_Query":private]=>
  487.   array(2) {
  488.     [0]=>
  489.     string(16) "init_query_flags"
  490.     [1]=>
  491.     string(15) "parse_tax_query"
  492.   }
  493. }
  494.  
  495. */
Add Comment
Please, Sign In to add comment