Home Forums General Issues Show ACF if is child of spec page Parent XYZ


Show ACF if is child of spec page Parent XYZ

  • Hello. I have a problem with the following condition for ACF fields to appear. I would like additional fields to appear when completing pages only if these pages are a child of a specific parent (not child general, but 1-st, 2-nd, 3-th… child of page XYZ).
    It look like that:

    Parent ABC
    -Child A
    Parent XYZ
    -Child 1
    –Child 2

    I would like to have displayed ACF custom fields when i’m filling pages being child of Parent XYZ (Child 1 and Child 2). No matter how many children Parent XYZ has and will have in future. The list of children will grow in future, so I want to avoid the condition show if it’s a child general, or show on “this” page. I want to have universal condition – show if is child of Parent XYZ, not Parent ABC, EFG, ETC. Is it possible?
    Thank you!

  • You should see a Page Parent location rule in the Pages section when adding a field group.

  • Thank you. But in location rules i couldn’t find any rule, to match my requirements.
    There are a lot of general settings, where I can’t specify the fields for children of a specific parent page. There are options generally for children, or parents. Not specyfied ones:(

  • There is most definitely a Page Parent location rule that allows you to select a specific parent page location rule for a field group but it may be a location rule only available in the Pro version.

  • Thanks for your answer, but it doesn’t solve my problem 🙁

  • The pro version solves your problem so other than telling you, “Buy the pro version if you need the pro functionality” or write your own location rule, not sure what answer you’re looking for. ACF Pro solves your problem, sounds like you just aren’t willing to buy it haha.

  • In the previous post, you only assumed that this functionality is in the premium version. If you want to help, printscreen me a rule that describes the situation. And then your answer will be valuable. And maybe it will encourage me to buy a plugin.

    And why the sarcasm? I won’t even mention any help in writing such a rule. I won’t even try. I wonder why there is a free version at all and the mentioned rules. It’s best to say buy PRO and be proud of yourself.

  • This is what you need:

    It allows you to specify an exact page parent (Parent XYZ) in your case. You can create a field group, select to show if Page Parent = Parent XYZ.

    I’ve had pro for so long I just don’t remember what isn’t in the free version so I suggested if you don’t see Page Parent, it could just be in the pro version, but that’s the rule that does the exact thing you’re asking for. The fact it’s in the repo for the free version suggests it isn’t a pro-only feature. I’d double-check your location rules. Best of luck!

  • I really appreciate your help. Thank you. I will try to implement it:)

  • 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:

    Copy code
    // 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.

  • Thank you Joyce. That’s not quite the point. I wanted to achieve it on the backend, not on frontend of page. So i wanted the fields to appear if I edit page, and page belongs to XYZ parent. Hope I’ve explained it right. Thanks again.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.