0

I don't know why, but for some reason neither parent or child_of are being accepted as arguments in get_posts that I'm using a foreach loop.

$sidebarReviews = get_posts(array(
    'child_of'       => get_ID_by_slug('testimonial-reviews'),
    'orderby'        => 'rand',
    'posts_per_page' => '6',
    'post_type'      => 'page' 
));

Note: the get_ID_by_slug is a custom function I have just to translate slugs into page IDs. This is working correctly.

However, when my foreach runs, it seems to pick up every page that's in my Wordpress database.

What's happening?

0

I think you confused arguments with those for term functions. :)

For posts the correct argument is post_parent.

| improve this answer | |
  • Hmm you're right, that must have slipped past me. I think I got confused between the note on the Codex saying, you can use the arguments in get_pages, of which I believe it's listed in there. – Lee Aug 19 '16 at 14:04
  • Right, get_pages() has those too... WordPress is consistent like that, ugh. :) – Rarst Aug 19 '16 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.