I won’t give a solution to your actual issue but I will show you how you can verify if current page is child of a specific top level page. If you need to check the current page has specific Parent page the you can do like this:
<?php
$currentPage = get_the_id();
$pageAncestors = get_post_ancestors($currentPage);
$hasParent = in_array($currentPage,$pageAncestors);
here get_post_ancestors
will return all parent id of that specific page as array and using in_array
you can validate if id exists. Read more about get_post_ancestors here.
Related Posts:
- Child pages on hierarchical Custom Post Types 404s
- Exclude the parent custom post-type posts only
- How to Display child post on his parent post with thumbnail and content in WordPress
- Advanced or not so advanced pre_get_posts query
- How to target a specific custom post type post and its all children and grandchildren?
- Display Child Pages of Custom Post Type Parent Page
- List of child custom post types lists all custom post types
- How do I display child post types in the parent post type template
- List child categories from parent category on custom taxonomy page
- Only looping through pages that have children or subpages
- Query to Exclude Child Pages from Custom Post Type Archive
- Custom post type loop without children
- Running get_posts within get_posts to get children of children
- Help understanding custom post type and children
- get children from current variable (taxonomy) via shortcode
- Nested custom post types templating
- How do I sort post listing by child post count?
- Custom Post Type children and grand-children in one list
- New post status for custom post type
- Adding Custom Post Type Counts to the Dashboard
- WordPress 4.4+ : How to revision CPT + metadata
- How can I filter posts by post_parent in the admin?
- Get Custom Taxonomy ID within loop
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Using Templates with Custom Post Type UI
- WordPress Custom Post Type Admin Page really slow
- How to setup a Custom Taxonomy Term template
- Creating a gallery of featured images from custom post type
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- Bulk 301 redirect for custom post type
- Custom post type: No posts found even if counter has a count
- ‘category__and’ for custom taxonomy?
- Custom field default value with counter
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Warning when attempting to edit/add custom post type
- Check if a specific custom field exists?
- How does register_post_type know how and which function to use from the add_action function?
- WordPress Create Post from front-end
- Custom post types archive redirect
- add custom field to custom post type
- Custom Taxonomy Archives on Custom Post type Page [duplicate]
- Custom post type search using $_SESSION and pre_get_posts
- Display custom fields from custom posts in RSS feed
- On update or create post redirect to current post position in list
- read_post meta capability for anonymous users
- custom post type pagination error 404
- Problems with image size on the server WordPress
- Search by tag name and category
- get_the_title() is returning results from previous loop
- Moving meta boxes in admin
- Can we create a custom post template for a specific page template
- Post-thumbnail only for specific post-types?
- Page as Archive page
- 3 random images from custom post type, each in a div with a diffrent class
- get_category_link() for custom post type does not include custom slug rewrite?
- Shortcode leaves no space for other elements?
- Conflict between wp_list_pages and get_posts – list pages not displaying
- How to make a pulldown menu display custom meta terms in a theme?
- Show All Custom Post Types On A Single Archive Page
- Show message when query has no posts
- Custom Search | check multiple meta_value for search value
- Foreach loop returning more than one item when querying taxonomy
- Change the properties of a custom post type after it’s been registered?
- Permalinks for single-[custom-post-types] not working
- Most viewed post of custom post type
- How to enable parent-child relationships and post attribute admin widget for posts
- Order Custom Post Type Archive by multiple values in functions.php
- Organize Existing Posts from the Admin Area to a New Category
- Manually adding or updating CPT automatically sets post_status of future
- Images not load on custom post type sidebar, related posts
- Custom post type page with parameter
- Filling custom post type posts from a rest api
- How to display posts with plugin (advanced custom fields) field groups?
- WordPress – display relationship between blog posts and custom posts
- Load info from customposttype into template page
- Multiple Loops In Tabs Only Displaying First Loop
- WP_Query to display number of custom post type filtered (order by) taxonomy
- Display post in sequence from different custom post_type
- Sort loop by custom field from different post type
- Custom post meta box as a sub form
- How to create groups like that in buddypress?
- Custom meta box data not saving
- Custom post type rewrite and wp_pagenavi interfering with each other
- Include template if a post is a single product
- Adding Information To All Posts Screen
- Render custom taxonomy query as single template
- Custom meta-box for all custom post types
- Retrieve a specific category of posts when using a custom post type
- General question about Parent and Child Post type relationships
- WordPress Load more posts by ajax not working
- What’s the best way to show custom post types? With page template it’s not perfect!
- Multiple while loops not functioning [closed]
- Listing all custom post types using a specific term on the said term’s template page, in groups
- How to write an if statement which reads: ‘if is this custom post type or a child of it do the following’?
- taxonomies or categories w/custom post
- Require Custom Taxonomy for Custom Type
- Post count for particular term
- Get post from custom post type that title is like custom string [closed]
- Custom Post Type urls not working
- Just the First Metabox what saves the data!