最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Get post and its children with WP_Query

programmeradmin1浏览0评论

I want the parent post and its children posts. I don't know the parent post ID, only that its post_password field is not empty.

It's very similar to this question except the post ID is not known in my case.

I want the parent post and its children posts. I don't know the parent post ID, only that its post_password field is not empty.

It's very similar to this question except the post ID is not known in my case.

Share Improve this question asked May 17, 2020 at 3:23 montrealistmontrealist 3,0741 gold badge22 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The question that is similar to your question, i took sample code from there. you can replace 'post_parent with this.

global $post;
$args = [
    'wpse_include_parent' => true,
    'post_parent'         => wp_get_post_parent_id( $post->ID ),
    'post_type'           => 'post'
    // Add additional arguments
];
$q = new WP_Query( $args );

This code will get the parents post id when you are inside children post

发布评论

评论列表(0)

  1. 暂无评论