Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End how to build a ‘post_parent’ array?

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #26352
    EamonnMac
    Member

    Hey guys! been a while…

    I’m trying to get the following line to work for WP:

    Code:
    query_posts (array(‘showposts’ =>100, ‘post_type’ =>’page’, ‘post_parent’ => ’80, 73, 67′ ));

    The page returns with a list of all pages rather than just the child pages of pages 80, 73 and 67 – so clearly my syntax is wrong. I’ve tried various combinations of if’s and and’s but it either comes back the same or not at all. What would the correct way of doing this be?

    Thanks in advance!
    Éamonn

    #65166

    Clearly a page can only have one (direct) parent, so the syntax is invalid – you must use ‘post_parent’ => 80.

    There are ways to query for a number of categories, tags or posts e.g. ‘post__in’ => array(1,5,7,89,102) will return all the posts with ids specified in the array, however there is no way to perform the same query based on the post parent.

    The simplest way to achieve this would appear to be through using a filter.

    Code:
    100, ‘post_type’ =>’page’, ‘post_status’ => ‘publish’) );
    ?>
    #65596
    EamonnMac
    Member

    Ta for that – sorry for the late response – I got bloody Swine Flu (not badly)!

    Given that I’ve already used the post_parent tag (with a different, single, value) twice already elsewhere on the same site, does changing the functions.php file not affect those other instances also? All these ‘posts’ are, in fact, pages so I can’t categorise them. Otherwise the ‘post_in’ tag would have been perfect…

    Thanks!

    #65597

    Stay away from the apple sauce then – :lol:

    If you call add_filter, then query_posts then immediately

    Code:
    remove_filter(‘posts_where’, ‘post_parent_in’);

    it will only affect that one query_posts call. Hope this answers your question.

    Cheers,
    Dave

    #65761
    EamonnMac
    Member

    Will do :D

    Ta again! I’ll give it a go.

    #108599
    barefoot87
    Participant

    Thanks! This was just what i was looking for.

    #111700
    carommedia
    Member

    Thanks!

    Is there a way to get paged results?

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.