Support

Account

Home Forums General Issues ACF Shortcode: Using taxonomy slug instead of post_id?

Helping

ACF Shortcode: Using taxonomy slug instead of post_id?

  • I’m using a repeater field on product pages to create an accordian with headings like “product specifications” and “about the manufacturer”.

    I’ve created a custom taxonomy called “manufacturers” with the following custom fields:

    an image field named “mft-logo” which is set to return the image url.
    a text field named “mtf-location” for displaying locations i.e. “New York City, NY”
    a text field named “mft-bio”

    Currently, I’m having success using the following shortcodes for the “About the Manfufacturer” section of the accordian:

    <img src="[acf field='mft-logo' post_id='term_44']">
    Headquarters: [acf field='mft-location' post_id='term_44']
    About this Manufacturer: [acf field='mft-bio' post_id='term_44']

    My goal is to be able to use the taxonomy slug (for example, ‘acme-usa’) instead of the post_id to expedite the work being done by product editors. It’s much easier for them to add a slug name (which will always be the name of the company using dashes instead of spaces) rather than manually looking at the backend of each manufacturer page to find out the post_id number.

    For example:

    <img src="[acf field="mft-logo" post_id="acme-usa"]>
    Headquarters: [acf field="mft-location" post_id="acme-usa"]
    About this manufacturer: [acf field='mft-bio' post_id='acme-usa']

    Is there any way to do this using slugs?

  • There isn’t any way to do this using the built in acf shortcode. You would need to build your own shortcode

    https://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/

    https://pagely.com/blog/creating-custom-shortcodes/

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

You must be logged in to reply to this topic.