Use the following to change the query from querying the current page to querying the parent of the current page:
query_posts( 'p='.$post->post_parent );
That will change the $wp_query
object to hold only the parent of the current post.
Note: this is untested.
update
You can also do it with a custom WP_Query
as so:
$args = array(
'p' => $post->post_parent
);
$parent = new WP_Query( $args );
while( $parent->have_posts() ) : $parent->the_post();
// loop stuff here
endwhile;
Related Posts:
- Display several random posts, but make sure a condition is met
- Can I create a loop with multiple post types and specify different $args for each post type?
- Conditional for a Single Post That Belongs to a Category?
- Get Custom post with ID
- Category as Class for Custom Post Type
- WP_Query to loop a Custom Field, Custom Post Types do not show
- Posts in Multiple Columns and Rows with one single loop
- Alphabetical sorting of custom post type – one letter per page
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- How to display the rest of categories on Portfolio filterable
- Function like in_category for custom taxonomies
- Get_post_meta() won’t return value
- Query Custom Post by Category
- How to get current post id of a custom post type in a loop using template singel-{custom type}.php?
- ‘category__and’ for custom taxonomy?
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- get_template_part for custom post type content not working
- How would I create a shortcode to display a custom post within a page or regular post?
- Creating Accordians in WordPress Theme
- How to insert content from another Custom Post type into Post?
- Display different content on homepage depending on post type
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- WP_Query orderby modified to include custom meta changes
- get_attached_media() on author page not working
- Calculate all custom field values in the post loop
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- Custom post type multiple loop by taxonomy term
- List custom taxonomy specific to one custom post type
- Custom post type, organized by categories
- What’s the WP way to load remaining custom posts?
- What to and how to proceed with CPT to make DB small and efficient?
- A custom post within a custom post
- get_the_title() is returning results from previous loop
- How can I group posts by months and years?
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- 3 random images from custom post type, each in a div with a diffrent class
- Displaying multiple post types on home page
- Shortcode leaves no space for other elements?
- Query to get child pages of current page and display it in action hook
- Get post format
- Display post from custom post type
- Use post in multiple places on a page with multiple posts
- List all Custom Post Type posts excluding certain Taxnomy term
- WordPress giving a 404 page when passing a year argument different than the current year
- Add Class according to the order of appearance
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- Permalinks for single-[custom-post-types] not working
- Drop down list with posts within the “add new” page
- How to show custom post type on homepage and in categories
- using the loop in custom meta is messing up ‘add new’ post type
- How can I increase the post count for custom post types only?
- Custom post type pagination error
- Add custom post type to query
- Checking for custom field in admin pages
- How can I loop at a Specific Taxonomy from a custom post type?
- Custom archive page for custom taxonomy and pagination issue
- Update query based on CPT / Post Type, show all sorted by date
- WordPress next post by ajax call on button click
- when looping through custom post data not appearing
- How to avoid duplicate posts queried from custom meta?
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- How to only get the content of post page while looping?
- I’m trying to create an if statement that will only display my button link for tickets if its under ‘admission-event’… what is wrong with my code?
- Why do my custom post type show up in all pages?
- ACF meta_key and meta_value break loop
- Looping to organize and display custom posts by category using PHP and WordPress
- Pagination for a cpt filtered with a category
- Staggering featured post using ‘sticky’
- My post loop needs to have 8 different post templates
- Mix Facebook and Twitter feed into custom posts
- next_posts_link() always generates second page link on custom post type
- Infinite scroll doesnt work
- Show posts for current taxonomy
- Excluding category from loop not working
- Multiple domains, Single database, 1 Parent/Master with all content, other domains/slaves with filtered content (based on “location” variable)
- Strange behavior on WP_query
- How to check if meta box value is false for all posts then do something based on that
- Tricky Custom post loop
- Custom taxonomy page template
- display news with pictures 3 small and one large (loop)
- Display posts from category in page
- Multiple Queries and Loops within CPT Archive
- Nested loop called with shortcode duplicating the content above the main loop
- Pagination not working with custom loop
- Display multiple custom post type lists on homepage – multiple loops
- Query Custom Post Type by Tag
- Loops running into each other
- Display by tag from different post types
- why get_post_meta is returning 0?
- Get Posts From A Certain Post Type In An ID Array
- Show search for data extracted from metabox
- Get all active posts that are tied to a custom taxonomy for a custom post type
- WPNavi pagination links not working on custom pages
- Group search results by post type, but having a unique heading for each section?
- Create a WordPress loop that shows posts from a custom post type + filters the posts by taxonomies while hiding empty taxonomies
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template