[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 21:38:50 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             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 If you pass both `child_of` and `meta_key/value` parameters to the
 `get_pages()` function, there are problems.  To reproduce:

 Create a page structure like so:

 Grandparent (id=1)
 -Parent (id=2)
 --Child (id=3)

 Add a custom field to the Child page.  Say `meta_key='bark'` and
 `meta_val='woof'`.

 Call

 {{{
 get_pages(array(
     'child_of'=>1,
     'meta_key'=>'bark',
     'meta_value'=>'woof'
 ));
 }}}

 And it will return an empty array.  The reason this is happening is
 because in the `get_pages` function (`wp-includes/post.php`) on line 4562,
 the `$pages` array only contains Child because it's been filtered by the
 `meta_key`, but `get_page_children()`, which is being used to determine
 which pages are `child_of`, requires the complete hierarchy of connected
 pages to determine which are children, and so it returns nothing.

 I hope this is helpful.  Obviously there are workarounds using loops and
 get_posts() and people are always suggesting you don't use get_pages() but
 anyhow, there it is, a bug report.  :)

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


More information about the wp-trac mailing list