WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Filter all child posts within post parent id (1 post)

  1. drewshen
    Member
    Posted 9 months ago #

    I have added a hook to functions.php using pre_get_posts to filter search results by post parent: $query->set( 'post_parent', $_GET['post_parent'] );

    This works fine with posts which explicitly have that post parent id value set. However, it is not returning 'child posts of the child posts', so to speak. So if for example the parent id is 262, and post 280 has a post parent of 262, it will be shown in the search results. However, posts with post parent id of 280 will not be shown even though technically they are contained in the 262 post parent. Hope this makes sense.

    What is the proper way to return all child posts of a post parent, child posts of child posts, all the way down?

    Any help is appreciated.

Reply

You must log in to post.

About this Topic