Is there a similar shortcode like described at https://www.advancedcustomfields.com/resources/shortcode/, but for fields attached to a taxonomy? I imagine the shortcode would look something like…
[acf field="field_name" taxonomy="taxonomy_name" term_id="1"]
If not, can this be a feature?
It would be something like this
[acf field="field_name" post_id="term_1"] // 1 is the term ID
I have a custom taxonomy called Agents with taxonomy slug agents. I created a custom field group called Agents. The fieldnames for the fields in the group are agent_name, agent_phone, agent_email and agent_picture.
I tried the above code like so:
[acf field="agent_name" post_id="agents"]
This did not return any values. How can I return custom fields attached to the agents taxonomy?
See my previous comment. “agents” is not a valid value for post_id. You must supply the ID that ACF needs. This is "term_{$term_id}"
You cannot add fields directly to a taxonomy. Fields are added to terms in that taxonomy. You need the term ID of the term where you are entering values into the ACF fields.
So how would I go about adding agents to Homes CPT? I thought create Taxonomy called agents and add terms which are the agents names like Jane Doe and John Doe. I attached custom fields to the taxonomy and it all looks good. I just can’t return the agents email, phone, name associated with the Home.
What you are trying to do is beyond the scope and capability of the ACF shortcode. The reason, I assume by reading your problem, is to show values from a term that the post in a CPT is assigned to.
If you want to do this with shortcodes then you must built your own shortcode that can get the post term in your custom taxonomy that is assigned to the post and get the fields from that term.
https://developer.wordpress.org/reference/functions/add_shortcode/
I am assigning an Agents taxonomy to Homes CPT. The Agents taxonomy has custom fields for the agents picture, name, email and phone.
I am limited to the themes abilities to return and show items in the grid. Right now it only allows me to show items of a taxonomy. Ideally I would create a CPT Agents and CPT Homes. Then somehow relate the two and show them in the grid.
Its a cool idea though right? I mean if I can attach the Agents taxonomy to the Home CPT with custom fields for the taxonomy for agent picture, name, email and phone its an easy solution.
Unfortunately I don’t have coding capabilities and was hoping you would be able to come up with a solution. (i.e. the shortcode)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
📣 “ACF Chat Fridays”
— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.