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]
- Remove the first 5 characters of the_title and orderby that
- Unread Repeater field IMG alt not working
- Unable to write multiple values back to ACF user field – PHP
- Update grandchild repeater field with value per row
- WordPress, AJAX and pre_get_posts using conditional tags
- selected option if current category is the value
- How to use thumbnail size of image if I’m only using src to get image
- Slick + PHP + ACF + JQuery slide reveal not working
- How to remove ?wp-mce-4103-20162941
- Customize position of social icons in upme plugin [closed]
- Why Won’t My Inputs in a form with a Get method work together?
- parts of url disappear when using # inside href=”” [closed]
- Settings API callback function inserts html quotes from nowhere
- Input data from email form not going to JSON file
- How to get the value of input hidden html from text editor to custom page template?
- Different post styles depending on category
- How create a Shortcode with hover and complex options
- How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
- Dot is not added at the end of href
- WordPress Multiple Navigation bars
- Position banner to right of logo in header – messed up my header file
- Commenting out unwated CSS/scripts in HTML with PHP
- How to separate HTML and WordPress files
- Add .htm extention to a custom taxonomy
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- Sort by page information by Ascending Numbers
- How do I add a custom css to all posts without affecting homepage css? [closed]
- If tag equals then show else show
- Make PHP work with HTML tags
- Noscript not working as it should in wordpress site
- Show latest posts in a plain HTML website custom widget [closed]
- How to convert select to HTML with PHP tags inside of it [closed]
- Advanced Custom Fields – display label and value only if value entered
- Advanced Custom Fields not displaying
- Is this spyware on my site or a real Java update?
- 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?
- Wrapping a Sidebar within
- Search WordPress using static html page
- Hide HTML element (by class or ID) with PHP
- Add Codepen animation as Preloader to WordPress
- Path for php file for inserting data through html form
- Function returns text instead of html [closed]
- Download PDF after CF7 form submission
- Printing HTML codes
- Widget back end radio button issue
- HTML escaping data with ajax requests
- How i can get post data from database when i am getting post id from url in wordpress
- How to retrieve the data from the sever and displaying it in a page?
- php within html within php
- Conditional statement for dates
- How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]
- How to execute html code inside php?
- How to remove coupon dropdown feature
- Add data-id attribute to child page links
- Add shortcode in my div
- How can I display a div ONLY if it is not a certain term page
- Don’t show certain div on front page?
- If ‘editor’ is empty, then
- Add class to DIV depending on page loaded
- WordPress plug-in for dynamic download link?
- HTML table attributes ignored
- Upload non-featured image to image field
- php esc_html_e with an html link inside not working
- Add html link in functions.php files of the theme
- Using ob_start and ob_get_clean with wordpress shortcode
- HTML Special Characters in URL string [closed]
- 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)
- How to edit HTML of my website on WordPress? [closed]
- How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)
- WordPress wp-admin redirect and exception
- How to remove the h6 tag for the entry-category Class
- Override user-edit.php to design own profile page
- Form search query – displaying ACF “Post Object” field as results
- wp_insert_post() with HTML tags using PHP
- How to rename woocommerce-billing-fields
- InnerBlocks with allowedBlocks not working with acf_register_block
- Prevent redirect to wp-login.php
- PHP contact form not redirecting [closed]
- Accessing values from ACF sub field (flexible content area) in PHP
- Can I set up a hover animation in CSS depending on a PHP conditional?
- How to Schedule Cronjobs for start of every month and year
- Get ACF options field in PHP acting as CSS
- Where can I find the inline-css of my theme header?
- ACF & Bootstrap Gallery Shows Blank Slides [closed]
- Handling PHP/HTML inside the output of a shortcode function
- Conditional multidimensional arrays and array_map
- ACF Repeater Pagination stopped working since upgrade to php7.2
- How can I count ACF sub_field with a certain value
- Make textarea required. Help [closed]
- Undefined index for default custom theme option
- what is the method to echo class attribute inside the i tag? [closed]
- WordPress forms submissions and PHP files
- Remove conditional tag from header