[wp-trac] [WordPress Trac] #36313: get_pages() child_of argument does not work in combination with meta_key/value query

WordPress Trac noreply at wordpress.org
Wed Mar 23 22:07:58 UTC 2016


#36313: get_pages() child_of argument does not work in combination with
meta_key/value query
-------------------------------+------------------------------
 Reporter:  MarcGuay           |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  4.4.2
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:
-------------------------------+------------------------------

Comment (by MarcGuay):

 Here's a proposed solution:

 {{{
         if ( $child_of || $hierarchical ) {

                 // Get new collection of all post_types queried for
                 $all_pages = get_posts(array('post_type' =>
 $r['post_type']));

                 // Get children based on child_of parameter
                 $_pages = get_page_children($child_of, $all_pages);

                 // And remove elements which were not in the $pages
 collection queried above
                 foreach ($_pages as $key=>$value){
                         if (!in_array($value,$pages)){
                                 unset($_pages[$key]);
                         }
                 }
                 $pages = $_pages;
         }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36313#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list