When a post (of ony type) is a child, its property post_parent
is a number with the parent’s post ID. Posts without a parent have a value 0
instead. So you can test this value:
if ( 0 === (int) $post->post_parent )
{
// show the post
}
Another option is a filter on pre_get_posts
(not tested, just an idea):
add_action( 'pre_get_posts','hide_children' );
function hide_children( $query )
{
remove_action( 'pre_get_posts', current_filter() );
if ( is_admin() or ! $query->is_main_query() )
return;
if ( ! $query->is_post_type_archive( 'your_post_type_name' ) )
return;
// only top level posts
$query->set( 'post_parent', 0 );
}
Related Posts:
- How do test if a post is a custom post type?
- Hook for post and page load
- Integrating a custom post type into a page hierarchy
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- Conditional for single-{post-type}.php
- Searching multiple custom post types and pages
- Return current page type
- Custom Post Type as Page parent
- How to add a post from a custom post type as the static page?
- Get page by template?
- Page as child in custom post type slug?
- is_singular() not working if called via callback function of admin-ajax.php
- Is it proper to create a page just to generate a listing page (eg. for a custom post type)
- TV Show database – Best way for structuring it?
- Is there a way to make a custom Page type?
- functions.php conditional tag only for custom post type
- Menu position (admin menu) of pages
- How to Add Pages Under Custom Post Type URL Structure?
- Exclude custom function content from certain pages
- Get template part based on custom taxonomy term
- Custom Posts on Different Pages
- Pagination with custom loop
- Include images from pages in wp search.php results in default wp search
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- How to create user personal pages with information from their meta profile fields?
- If on term-page -> get the current term?
- Exclude Custom Post Type & Pages From Auto-Tag Function
- Display “Post 2 of 4” on single post page?
- custom post type upcoming post and past post
- changing default comment form arguments [duplicate]
- Custom Post Type Name Causing Problem
- Make custom post type display as a page
- wp_list_pages doesn’t work in hierarchical custom post type
- is_page_template not working as expected
- Multiple portfolios with one custom post type?
- Is it possible to use pages to apply static content to each taxonomy level?
- Making pages also serve as taxonomies? Or give full pages to taxonomies?
- Share parent path between Custom Post Types and Pages?
- ‘Pages’ widget alternative for custom post types?
- Custom Blog Post Listing in Genesis Sample Child Theme
- Check if admin is editing page or custom post type
- Pull in custom content types into page template
- custom posts on different page
- Trying to edit the single page from a Custom Post
- if custom posts type exists and there are posts load script
- How do I fix permalinks for custom post types that has the same slug as a page?
- Need help targeting a custom post type with conditional tags
- Why would this IF statement not work? [closed]
- custom comments on specific post type
- Create custom PAGE with register_post_type
- Excluding custom post types
- Should I use custom taxonomy or custom post type
- Disable featured image
- Making a custom help center page
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- create a template page for a post
- Page vs Custom Post Types Differences/Issues
- Register widget only page is a singular of custom post type
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Is there a conditional tag to determine whether the post is _any_ custom post type?
- Conditional Query of Custom Post Type and custom taxonomy
- Exclude pages in archives results
- Make parts of your wordpress website completely built with data from external APIs?
- Trouble with CPT Child 404
- Database to page routing API?
- Assign same parrent Page to pages AND custom post types
- Allow Static Page Load Dynamic Child Pages
- No Permission to add new Page, Post or CPT with Admin role
- Static page determines as home, but it is not
- Cannot use pages created on WP
- Custom metabox fields not saving when limited to a certain CPT
- Can not hook into custom post type template with: is_page() conditional?
- Use the page picker from wordpress menu creation page
- Different post types arranged on one page
- How to display data with pagaination on backend?
- archive.php can’t find categorized posts
- Pulling Content from Existing Database
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- Excerpt for each post type and for is_front_page
- How to Associate Posts with Pages
- Diffrent search templates for different post types
- Programmatically Split A Post Into Multiple Pages
- Conditional Tags If Custom Post Parent & Child?
- Why are my wp urls showing page not found?
- query_post while (have post) get_template_part()?
- “regular” pages not found after changing permalink
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- Custom Post Query Combined with Conditional Tags
- Using custom post types within a section of a template
- Page that ‘subscribes’ to multiple categories
- How to store queried custom data and use it in multiple pages?
- Highlight specific menu item when custom post is page
- Conditional statement checking two conditions for CPT and Custom Taxonomy [closed]
- strange conditional tag behaviour [duplicate]
- How do I hide single category post on my post page
- Custom post type is_singular condtional not working when managing sidebar display
- How to add a regular page under a custom post type?
- An script/Plugin for automatic page creation per term
- Why using archive pages at all?
- Subpage for Custom Post Type