My question is how can I automatically get the parent post content on
every child
Your code should work just like it is: if you have a parent and you add any number of children to this parent (wpse121567_get_cpt_hierarchy
return ‘debate-child’ for them), your code will show the content of parent post.
and if I add more content from the dashboard to be added after the
content from the parent element?
for this, where you have:
global $post;
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
echo '<div>' . apply_filters( 'the_content', $parent->post_content ) . '</div>';
replace with
the_post();
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
$content = apply_filters( 'the_content', $parent->post_content ) . get_the_content();
echo '<div>' . $content . '</div>';
Related Posts:
- How should I structure complex content hierarchies?
- Query all post types but limit to parents
- Custom post type hierarchical loop in Homepage
- Integrating a custom post type into a page hierarchy
- Display all posts starting with given letter?
- Nested custom post types with permalinks
- wp_pagenavi() with custom wp_query()?
- Display a list of child posts on parent posts of a custom post type
- Custom Post Type Pagination Not Working On Archive Page
- Child pages on hierarchical Custom Post Types 404s
- Custom Post Type ‘hierarchical’ Help!
- Pagination go to first page if i’m on last post
- Grossly inefficient wordpress loops!
- Order custom posts by taxonomy?
- Remove tinyMCE from admin and replace with textarea
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- exclude custom post type by meta key in wp_query
- IF statement in a do_shortcode
- Get the title of custom post type in another loop
- Parent / Child formatting in a list of post of a custom post type
- How to list custom post types?
- Unable to get post content from custom post type loop
- Automatically populate a hierarchical taxonomy from a custom field
- How to check if “is single” page
- Using pre_get_posts to filter one loop in a multiloop archive
- Pass the_post() as a parameter
- Should I use custom taxonomy or custom post type
- get_template_part and template file names
- Creating select dropdown with parent-level custom post types
- Show one item per category of a custom post type
- Loop custom taxonomy to get lists of cutom post types?
- Hierarchical Custom Post Types in Array
- Multiple Loops On Custom Post Type Template?
- Show a Category X’s custom post type on Category X archive page?
- Custom Tag Description unable to display just below and outside of the Loop
- Rewrites/query for multiple hierarchical custom post types
- Displaying Custom Posts on a Page
- Custom Post Type within the Loop on Homepage (Page Template)
- Custom while loop for hierarchical display of a taxonomy
- Custom Theme With Custom Loops
- Create more category hierarchical depth for custom post type/taxonomy plugin (widget)
- Listing all term items alphabetically / sorting loop
- Does WP have a global of $id?
- Wrapping x posts in html without leaving empty html
- Bootstrap accordion looping through posts incorrectly
- the_post() is printing titles in page footer
- Post loop count is not in order
- hide specific div on single.php [closed]
- Looping Through Categories of a CPT
- How do you output an unknown number of images in a custom post type with desired markup?
- Get data from PHP to JavaScript to set position of each post on front page
- How to query for posts (hierarchical custom post type) that have children but are NOT top level?
- assign different templates to custom post type with homepage loop
- Assign a template to a custom post type when displayed by the main loop on the home page
- Ideas on how to organize a project [closed]
- The loop does not show users
- Displaying information from custom field on custom post type
- Display only a single CPT
- Control Loop Within Loop
- How do I enforce a specific custom post type on the loop
- CPT archive page – show one post from each taxonomy term
- How do i display post from a taxonomy term?
- How do I list a custom field and custom taxonomies for each result in a loop?
- WordPress general content best pratices
- Show the categories the current post has
- Pagination not working in custom post type. Help
- How to convert hierarchical Pages to hierarchical Custom Post Types? Slugs get a number as if they were duplicates
- How to create an IF statement in the Main Loop for Custom Post Types
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- How to output and alert message when updating a post
- Loop (for search results) returning right posts, but wrong post type
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- WordPress trying to query two custom types to get child from the parent
- Display title of all custom posts from same taxonomy term on a custom post template
- get_permalink() of page the enclosing page not posts
- Hierarchical Custom Post Type Walker?
- How to display user-defined / custom post in wordpress?
- WordPress query in which condition uses custom field
- WordPress loop add heading before first of type
- Error in WP Query. If variable is empty it is displaying previous post value
- Custom Post Hierarchy and users
- How to keep a CPT stick to specific position?
- Is it possible to add query parameters on the archive page?
- Pagination in custom post type page template
- Custom post type archive pagination with HTML5Blank theme?
- Custom Post Type Order Index Loop
- taxonomy term names in custom post type permalink structure
- WordPress nested loop not working
- Order by custom field attribute
- Display Custom Taxonomy of custom post type
- Create custom post order (with custom post type meta)
- next_posts_link returns same content of 1st page
- Custom Post Types and 404 Pages
- Specifying Default Template for Hierarchal Custom Post Type [duplicate]
- Hierarchical Custom Post Types
- How to loop through a custom post type using a shortcode and output each element in the loop using shortcodes
- Filter page ID outside the loop and order
- How can I show posts with the same tag?
- How to add a regular page under a custom post type?
- WordPress post objects in one parent post object