If I understand your question correctly, you want to display an Advanced Custom Fields (ACF) field if the current page is a child page of a specific parent page, called “Parent XYZ.”
If I understand your question correctly, you want to display an Advanced Custom Fields (ACF) field if the current page is a child page of a specific parent page, called “Parent XYZ.”
To achieve this, you can use the get_post_ancestors() function to check if the current page has “Parent XYZ” as its parent page. If it does, then you can use the get_field() function to display the value of the ACF field.
Here is an example code snippet that you can use:
php
Copy code
<?php
// Get the current post ID
$current_id = get_the_ID();
// Get the list of ancestor IDs for the current post
$ancestors = get_post_ancestors($current_id);
// Check if “Parent XYZ” is in the list of ancestor IDs
if (in_array($parent_xyz_id, $ancestors)) {
// Display the value of the ACF field
$field_value = get_field(‘your_acf_field_name’);
echo $field_value;
}
?>
In this code, replace your_acf_field_name with the name of your ACF field, and $parent_xyz_id with the ID of the “Parent XYZ” page.