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
Related Posts:
- Return parent post with its children using WP_Query?
- list pages using page.php and NOT page-{slug}.php
- wp list pages using meta box value
- why ignore_sticky_posts in sticky post query
- get custom post type by tag
- Does tax_query really beats meta_query in all situations?
- WP_Query by post ID doesn’t work if post is in custom post_status
- Using WP_Query To Get Posts Randomly From today
- How to know which one is the main query?
- WP_Query orderby taxonomy term value (numeric)
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- How to order posts by custom WP role?
- WP Query and order by particular specified IDs
- Get the post permalink within the loop but without additional DB query
- Display revision if post status is pending
- Meta query field order together with post_date order causes posts without the meta field to be unordered
- How To Remove/hide some specific categories from two different categories widget from sidebar
- WP Query search for attachments and their exact title
- How to add another parameters to WP_Query?
- Display link to taxonomy archive only if it has posts with certain custom field values
- How to display posts month by month?
- Display posts with date wordpress default
- WP Query Exclude and Start by Menu Order Offset
- Pagination is broken and I need help fixing it
- Query total number of posts
- Category attribute not working in custom shortcode
- WP_Query Excluding pages with Order is 0
- How to display a posts 1 year ago with custom WP_Query loop?
- Check on which page specific result exist
- WC displaying products from category
- Show all post for a given category
- Loop returning only 1 result
- Fetch posts that match term slug first two letters (wp query)
- pagination with numbers for WP_User_Query
- How does one perform a sub query with different post types
- Stuck in the query loop
- Query Page Content From Theme Options?
- Filter wordpress post categories with jquery/ajax and pagination?
- Taxonomy order exception for specific term
- next_post_link / previous_post_link not working with WP_Query
- How to Create a Random List of Child Pages
- How to display the featured image for each post?
- How do I amend wp_query before it is run/executed?
- Post Thumbnail URL isn’t pulling into the background of div
- Is there a way to make this kind of loop shorter and nicer?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- WP Query ordering on a meta field for posts with a date in the future not ordering by datetime
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- Pagination on template page for custom query redirecting to index.php
- how to get Nearby zipcode
- 2 column recent post query not respecting float right [closed]
- Meta query compare for ID’s greater than specific ID
- WP_Query->request has a limit
- Slider won’t work with custom query
- wordpress udpate query not equal to
- How to generate feed for custom template
- Add parameter to first post only
- Ignore image urls in wp_query search
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Why does apply_filters behave different inside and outside a loop?
- Having a variable based on $post_count increase when i move to the next page of results
- Post order by custom fields
- WP Query and multiple pages
- meta_query where the meta value is not the post title
- Elementor posts custom query based on tag [closed]
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- Is WP Query skipping to check next post when an argument is not met?
- How do you do a meta query on an encrypted field?
- meta_query is overriding default search
- Custom Woocommerce Product Query
- Multiple WP_Query args combinations according to post type
- How can I write a WP_Query that is this specific?
- in_the_loop() issue with custom query
- Pagination inside the blog page not working
- How to restrict add media library only to images of the same post family?
- How to query most recent post for each author?
- Custom Query Pagination not working on static front page
- Post Template Query with WP_Query?
- Wp Query sort order
- get_posts query caching?
- Adding additional taxonomies to wordpress taxonomy page
- why doesn’t this pre_get_posts code work?
- pre_get_posts with WP_Query to prevent posts from specific tags
- Custom taxonomy and query multi conditions
- Best way to Order Post in Home without a plugin
- Retrieving category pages from subcategory returns empty sets
- How to get query results for the next page
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- Get post closest to today
- Multiple loop for “featured” items returns wrong posts
- Get WP_Query query after execution?
- Pagination in custom query not working [duplicate]
- Query string form $_GET[‘value’] is not working as meta value in wp_query
- query_posts problem – need help
- 294 Queries on Mainpage of WordPress
- Pagination on custom post type not working
- I want to capture the last day’s (today) posts in a category in the numbered order in acf
- How do I have multiple metaqueries inside one wordpress query
- Can I use WP_Query to find a post with a particular menu_order?