-
Agent8
Hi,
Can you please help me with setting up a couple of buttons in an element or point me in the right direction for documentation?
I’ve got a ACF Custom Post Type of People with a People Profile field group. In here I have a field for Phone and Email.
In a Post Template for Person I have two buttons created with dummy content but I need to get these to dynamically pull in and display on the button the phone number and email address respectively and also get the link to be applied to the buttons as a tel: and mailto: so they work when you click on them.
Presumably I can pull in the dynamic data but I need to use the right Post Meta values in relation to the ACF name of things? I need to try and also get the formatting as it is so T: and E: appear before the field content.
Thanks,
Nick. -
Hi Nick,
Try setting the dynamic tag for button text to
t: {{group_field_name.phone_sub_field_name}}ande: {{group_field_name.email_sub_field_name}},And set the dynamic tag for the button link to
tel:{{group_field_name.phone_sub_field_name}}andmailto: {{group_field_name.email_sub_field_name}} -
Agent8
Many thanks Ying.
I’ve tried that and can only get it to display as text as opposed to pull in the data.
To simplify things I changed the field group to peopleprofile. Phone and Email should both be lowercase for field name as well. These are applied on the two buttons at the moment.
I’ve tried it with both a dot between the group and field parts and an underscore. I was reading ACF documentation but perhaps that relates to PHP usage.
Neither work. The editor removes the preview option as soon as I use these texts. I’m not sure if I’m doing something wrong with the editor there that is breaking things.
Thanks,
Nick. -
George
Hi Nick,
The issue is how ACF stores group subfields. In the database, a subfield inside a group is saved under a flattened key —
groupname_subfieldname, joined by a single underscore (no dot). So for your setup the keys arepeopleprofile_phoneandpeopleprofile_email.Set the button text dynamic tags to:
t: {{post_meta key:peopleprofile_phone}}
e: {{post_meta key:peopleprofile_email}}And the button link fields to:
tel:{{post_meta key:peopleprofile_phone}}
mailto:{{post_meta key:peopleprofile_email}}The
key:parameter is what was missing before — that tells the tag exactly which stored meta key to read. -
Agent8
Thanks George,
I’ve tried applying that and the editor likes it. Goes to preview mode. But on refreshing the live page the buttons are disappearing so there’s something not right.
The Field Group was originally ‘People Profile’ with a space and I edited it to peopleprofile to simplify it. I’m not sure if the database side of things will update that after my change to lowercase and remove the space. I’ve tried it with a underscore and hyphen between the two words of the field group name. No Luck.
I also tried using the field group key group_68da5b5f14e04 in place of the name but again no luck.
-
George
Hi Nick,
That behaviour makes sense. Renaming the field group doesn’t rewrite the values already stored in the database — those were saved under the original field name, so the tag now points at a key that no longer matches what’s stored. The buttons disappear because the tag resolves to empty, and an empty
tel:/mailto:collapses the button.Two things to check:
- In ACF, open the field group and look at the Field Name of the group itself (not the label at the top). The label can be “People Profile” while the name is something else entirely — that name is what forms the meta key prefix. Whatever it currently reads, the keys are
thatname_phoneandthatname_email. - Renaming doesn’t update already-saved data. Open each of your People posts and hit Update to re-save them — that forces ACF to write the values under the current field name. Then the tag will match.
One note:
group_68da5b5f14e04is ACF’s internal field-group key, not a meta key, so GB’s Post Meta tag can’t read from it.Once you’ve confirmed the group’s Field Name and re-saved the two posts, retry:
{{post_meta key:fieldname_phone}} - In ACF, open the field group and look at the Field Name of the group itself (not the label at the top). The label can be “People Profile” while the name is something else entirely — that name is what forms the meta key prefix. Whatever it currently reads, the keys are
-
Agent8
Ok thanks George,
I must be looking in the wrong place as I don’t see a different place showing the Field Group name. Other than the ID number in the page URL. There is just one instance of the name/title at the top that is editable. I can see a slug panel lower down but that doesn’t work.
I’m just not seeing it. I tried resaving the Andrea People post as well. I exported the ACF data to Json and looked in there and it all appears to be peopleprofile. Although I know originally I saved it as two words with title case.
Can you please have a look at the admin screen and tell me what I’m missing? I’m going round in circles. Logon in private info.
The element I’m editing is Template Person.
Thanks.
-
George
Hi Nick,
Ok, first of all, there is no group ACF field in play here, the fields are all flat inside the peopleprofile field group. The Phone field type is the problem. It’s currently set up as a Checkbox field with preset choices, and that’s why the buttons collapse on the front end.
A checkbox stores its value as an array (even for a single selection), so the dynamic tag pulls back serialised data rather than a plain number — and an empty/malformed
tel:link makes the button disappear. The “Add new choice” box you’ve been using also writes into the field’s shared choice list rather than storing a value cleanly against each person.The fix is to change the field type:
- Edit the Phone field and change Field Type from Checkbox to Text.
- For Email leaving it as an email field should be fine or you can switch it to.
- Re-enter each person’s phone number in the Text field and update the post.
Once Phone is a Text field, your existing tags will work as-is:
{{post_meta key:phone}}for the text,tel:{{post_meta key:phone}}for the link.The Email field, being a single value, will behave the same way:
{{post_meta key:email}}andmailto:{{post_meta key:email}}.
- You must be logged in to reply to this topic.