Use get_post_ancestors( $post )
. It returns an array of post IDs. The parent ID is the first entry, the grand parent the second and so on.
$ancestors = get_post_ancestors( $post );
if ( is_page( 'about' ) || in_array( '29', $ancestors ) )
{
echo "This is About or one of its descendants";
}
elseif ( is_page( 'contact' ) || in_array( '31', $ancestors ) )
{
echo "This is Contact or one of its descendants";
}
Related Posts:
- ACF page while loop breaks footer while loop
- Creating an image from a custom field
- Advanced custom fields Repeater conditional statement not working [closed]
- advanced custom fields: repeater field within conditional statement [closed]
- How do I make an HTML table from a database table?
- How to get the custom header image’s alt text?
- Modify previous and next text from pagination links
- Correct regex for wp_embed_register_handler
- Show content if parent page has children
- Calling a method from functions.php on a click of a button
- How to Explode a Textarea Field and Echo each line separately, wrapped with HTML
- How to add a post or page tag to the list of classes appearing in the body tag’s class attribute?
- WordPress Wysiwyg Content not being displayed
- When is is_admin() available?
- Check if current page is wp-admin
- HTML table from shortcode with multiple parameters
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Missing sidebar parameter “fix” – before_content
- How Display Posts on category
- How to get the POST TITLE using the POST ID?
- Embed html in php code
- Output ACF repeater on frontend user’s profile page (created with Ultimate Member) [closed]
- Unread Repeater field IMG alt not working
- Customize position of social icons in upme plugin [closed]
- Position banner to right of logo in header – messed up my header file
- How to separate HTML and WordPress files
- Syntax error when I try to insert my loop into an unordered list? [closed]
- How to make modifications only to certain elements of an HTML string on the server-side?
- Printing HTML codes
- How to retrieve the data from the sever and displaying it in a page?
- How to execute html code inside php?
- Add data-id attribute to child page links
- Add class to DIV depending on page loaded
- ACF put a comma after the last repeater field value [closed]
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- wp_insert_post() with HTML tags using PHP
- Conditional multidimensional arrays and array_map
- Remove   from the_excerpt
- ACF Unexpected T_CONSTANT_ENCAPSED_STRING [closed]
- “if parent category is” conditional?
- Conditional for Post Format
- Custom forms with HTML
- Foreach loop is unexpectedly outputting an extra empty a tag
- how to changes mobile menu toggle breakpoint in WordPress
- How to store checkbox data for individual users?
- PHP inside echo HTML
- html form: redirect page after form completes submit function and posts data
- WordPress Post Block Element not properly parsed with the_content filter
- Get main parent category for post (WordPress/Advanced Custom Fields)
- Add other class content with reference class value
- What are the advantages/disadvantages of ways to use php template files?
- Configure WordPress to Use Responsive Image Rendering
- HTML comment cause issue in functions.php script root
- Slug duplicates once clicking on link
- If Statement is Ignored?
- Remove span tags from WooCommerce Downloads page
- Query on a repeater date (acf)
- How to enable HTML tags in category description without breaking the category page
- How can i create a function tag in my plugin
- Can’t display anything through homepage text editor
- How to find and delete a menu item in php?
- make p tag collapsed after 3 rows
- My single.php page skips the first div tag
- ACF – Can’t get custom post type by taxonomy
- ElseIf Statement with ACF Group field
- opens like sitename.com/URL
- WordPress Slider is not working
- Possible to edit custom date field and display?
- ACF – Get ID of relationship field in flexible content
- How to display post meta bellow every posts
- Get list of posts from attachment
- Pulling Products from an API
- Scheduling a post using publish date from a custom field. Resulting post is set as published in the future instead of scheduled
- Switch position of elements in the footer [closed]
- Can’t get_users info by using json_encode
- scroll scrpit to particular button position to next id when click button
- Position a repeated article blocks
- Code works on page-example.php by not category-example.php
- ACF Images If/else
- Page returning ID from array, how to return the correct values for post in acf wordpress
- Add options to WordPress backend
- WordPress HTML Helper
- How to define Og Meta Tags in header using conditions [duplicate]
- get_post_meta is always empty when I use wp_mail
- the_post_thumbnail unless video id is added
- Save Option on Database
- Add comma between variables [closed]
- Implement “No related posts for this entry” into the loop?
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- ACF repeater image in video poster with jquery
- Load slideshow.css file only if Slideshow is checked / on
- Advanced Custom Fields Show PHP in Text Areas
- Sorting Problem
- Add topbar to static html page
- ‘This Field is Required.’ is Not Displaying on CF7 [closed]
- Why do I get a 404 error on my custom post type archive pagination?
- change div text and link for logged in users
- Font Awesome Icons as squares [closed]
- How to modify default tags in wp_head()
- ACF number less than comparison not working