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
- Custom Post Types hierarchy and rewrite
- How do I know the ‘meta_key’ for ordering my custom post type
- How can you use one database with multisite
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Custom Theme With Custom Loops
- Custom Post Types strange pagination problem
- Create more category hierarchical depth for custom post type/taxonomy plugin (widget)
- Hierarchial Custom Post Types/Taxonomies
- Hierarchical permalinks for custom post type and taxonomy
- using wp_update_post for updating custom post type
- Custom post type conditional in loop
- Listing all term items alphabetically / sorting loop
- Display related custom taxonomy posts in sidebar
- Custom post type Permalinks with hierarchical Taxonomies
- pagination not working for category.php (custom post types in categories)
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- Create a permalink structure with custom taxonomies and custom post types gives 404
- How do I control the output of a custom post type in the loop?
- Display custom post type posts first, then default posts
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Three Most Recent Posts, One Per Term
- Targeting custom post type
- Does WP have a global of $id?
- WordPress Loop if/else
- get_the_title() is returning results from previous loop
- Custom Post Loop pulling all custom posts, not just one
- Conditional for a Single Post That Belongs to a Category?
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Custom Post Type single.php template only shows the latest post
- Sort posts in loop by the WooCommerce Membership of the author
- Including all post id’s of a custom post type into an array
- How to include custom post type posts on a page?
- 4 column-loop ordered alphabetically with entries grouped (and labeled) by their first letter
- Tag page only display 10 posts
- How can I group posts by months and years?
- Pagination Error : Duplicate argument being outputted
- get_post_type is always post
- Multiple Custom Post Type queries, how to DRY it up
- Custon Content within WordPress Loop
- Custom Post type & Taxonomy 404
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Bootstrap accordion looping through posts incorrectly
- Main query not querying any posts in custom taxonomy template
- Loop increase number
- Custom post type showing same Post on all Pages
- get_post_meta is not working inside shortcode
- Using wp_query to modify the loop in index.php for a CPT
- the_post() is printing titles in page footer
- Is it safe to change a Custom Post Type from “hierarchical:false” to “hierarchical:true”?
- Custom WP_Query doesn’t display all posts
- Query & the_content() is showing in the header
- Create Array from custom post type to display a slider
- Move Genesis Single Page/Single Post Title
- page template for custom post type
- 3 random images from custom post type, each in a div with a diffrent class
- Two column layout with alphabetical ordering
- Post loop count is not in order
- Control content before and after custom post type loop
- Listing custom post types on archive page with array
- get_pagination not working on a custom post type query (using WP_Query)
- How to Make infinite loop of post
- WP_Query with custom post type ID
- Displaying multiple post types on home page
- looping though custom post types and only return results in a given taxonomy
- Shortcode leaves no space for other elements?
- How to conditionally add Custom Post Type to Front Page
- Dynamically insert code to custom post type loop
- hide specific div on single.php [closed]
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Pagination not working on custom query on a page
- Loop through posts of only 2 statuses
- Looping Through Categories of a CPT
- Search Filter CPT, Custom Loop
- 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
- Pull in taxonomy field of custom post type in new query
- How to add a lightbox to class mix?
- Templates for hierarchical custom post type
- custom hierarchical taxonomy and custom post type list contains surplus posts
- display posts of custom post type with custom taxonomy
- Creating a non-hierarchical Taxonomy that behaves like categories
- Query to get child pages of current page and display it in action hook
- Custom Post Type not showing in main loop
- My custom taxonomy is only displaying 1 of 3 terms
- Add more than one custom post type to wordpress home page post loop
- get custom post type value in header.php [closed]
- 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
- Migrating Hierarchal Taxonomy Categories Between Post Types
- Get post content from another section in custom single page
- Get post format
- Custom wordpress loop
- Assign a template to a custom post type when displayed by the main loop on the home page
- Custom Post type content within a slider
- Trying to add a class to post links