Support

Account

Home Forums ACF PRO Shortcode for fields attached to taxonomies

Solving

Shortcode for fields attached to taxonomies

  • 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}"

  • Where would I find the id for the taxonomy?

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

    Agents

    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)

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

You must be logged in to reply to this topic.