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.

list of posts in the database with post parent and its children highlighted

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

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.