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
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- Custom Post Type as Page parent
- How to add a post from a custom post type as the static page?
- Page as child in custom post type slug?
- Is it proper to create a page just to generate a listing page (eg. for a custom post type)
- 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
- Exclude Custom Post Type & Pages From Auto-Tag Function
- Display “Post 2 of 4” on single post page?
- changing default comment form arguments [duplicate]
- 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?
- 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
- Pull in custom content types into page template
- 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
- Disable featured image
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Page vs Custom Post Types Differences/Issues
- Register widget only page is a singular of custom post type
- Is there a conditional tag to determine whether the post is _any_ custom post type?
- Exclude pages in archives results
- Make parts of your wordpress website completely built with data from external APIs?
- Assign same parrent Page to pages AND custom post types
- No Permission to add new Page, Post or CPT with Admin role
- Show Custom Post Type meta boxes only on Page Edit
- Why does my content disapear when I make a page to match an archive name?
- How to use Custom Page Templates for hierarchical Custom Post Type
- Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms
- Custom Post Conditional for Parent & Child Single.php?
- Top Level pages in wordpress giving 404, but child pages working fine
- Why is get_pages() returning a boolean?
- Pros and cons of a custom page vs custom post type template file
- How to include custom post type posts on a page?
- Including link to custom post type in ‘wp_list_pages’ function
- the_content(); of custom post type treated as an array or object
- Can I change my post type to anything and my site still work?
- Page listing Custom Posts
- Display an authors post on a single page only when they are logged in
- Why are some of my custom posts not showing up on my page?
- Conflict between wp_list_pages and get_posts – list pages not displaying
- Hide Status Option From WordPress Publish Metabox and Rename Published on:
- Showing taxonomy terms on custom post type
- Check if custom post is a parent?
- How to set the mainpage of a custom post type?
- Setting a homepage – doesn’t seem to work
- Redirect to URL if x number of days passed
- If tag exists, then echo once
- wp_dropdown_pages with tax_query clause
- Am I mixing up the concept of posts pages and categories?
- Getting subpage of subpage – Custom posts
- Tag template not returning posts [closed]
- Does “Custom Post Type” can have page hierarhy option?
- Use conditionals with wp_enqueue_style to attach stylesheet according to post type displayed
- How to set a ‘page’ as parent of a custom post type?
- Add custom template ‘sub-page’ to Custom Post type?
- Metabox collapsed by default
- How can I check the rewrite slug of current post type listing page
- Create Custom page with custom domain
- Do not show child pages within a file page
- Show posts from custom post type sorted by category/taxonomy on a one-pager/page
- Custom post types & Pages hierarchy – Error 404
- How to add custom PHP code in post header?
- How to make “single post” permalink maintain it’s sub-page structure
- Include images from pages in wp search.php results in default wp search
- WordPress Contents Migration
- Creating Slider in wordpress theme with custom post
- conditional based upon the count of current user’s published custom posts
- Cannot use pages created on WP
- Custom metabox fields not saving when limited to a certain CPT
- Use the page picker from wordpress menu creation page
- 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?
- How to Associate Posts with Pages
- Diffrent search templates for different post types
- Conditional Tags If Custom Post Parent & Child?
- Why are my wp urls showing page not found?
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- 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]
- How do I hide single category post on my post page
- How to add a regular page under a custom post type?
- An script/Plugin for automatic page creation per term