Support

Account

Home Forums General Issues Rendering ACF Shortcode inside Tag Description

Solved

Rendering ACF Shortcode inside Tag Description

  • I wanted to render an acf (Advanced Custom Fields) shortcode inside the tag description. While other shortcodes were rendered successfully, the acf shortcode I added didn’t seem to work. Can someone please help? Thank you so much!

    I added [acf field="this_meta_data"] to the tag description but it didn’t render.

  • Perhaps add this to your functions.php (from https://www.advancedcustomfields.com/resources/acf-format_value/)

    add_filter('acf/format_value/name=this_meta_data', 'do_shortcode');

  • Thank you @andisaleh , I added it to my site but the acf shortcode is still not rendering.

    I also added

    add_filter('tag_description', 'do_shortcode');
    add_filter( 'term_description', 'do_shortcode' );

    but nothing seems to work so far.

    Thank you!

  • Can any power user @hube2 help?

  • You’re going to have to supply more information. What does

    shortcode inside the tag description.

    mean? Please give as much detail as possible because I really don’t understand from what I’ve read what you are trying to do.

  • @hube2

    Sorry for the confusion. Please see the screenshot and I hope it would help better understand my situation.

    In short, I created a group field and a text field for all tags. Then I populated the text field and inserted the acf shortcode to the tag description area.

    Screenshot: https://ibb.co/S7g5D9x

    Thank you so much!

  • Hi @hube2 thank you. I tried that solution before posting here.

    I’m not sure about category description but in tag description, other shortcodes work just fine without any modification made to the functions.php. Only acf shortcodes are not working and that was why I asked for help here.

  • ahh,

    the acf shortcode will not work there without supplying the post ID

    
    [acf field="field_name" post_id="term_XX"]
    

    where XX is the term ID

  • Hi @hube2 thank you so much. It works! In post content and if I want to render an acf shortcode, I don’t need to specify the post ID and it works flawlessly. I was wondering if it is a way to get the current term_id without manually adding it. My situation is that I have many tags in my old site.

    Again, thank you for great help.

  • To be honest, it should be working without supplying the ID, but that would depend on where you are trying to show the description. Give me more details about the page where you are trying to display the value and how the term is retrieved. Is this on the single term page? or something else.

  • Hi @hube2 , I’m just using the tag description out of box for posts but only adding an acf custom field to it.

    The acf field is just a text field with simple html code, because I wanted to show a featured image there. This can be achieved by using other plugins but I wanted to use acf in case I want to add more than images in the future. I was surprised to know I had to tell acf the term_id because I thought acf shortcodes would work inside tag_descriptiion the same as it would inside post_content.

  • That does not help me at all.

    ACF detects the ID to use by using get_queryied_object().

    And it only works on pages where that function returns a Post , Term or User.

    It will not work on an archive page for any post type and it will not work on a page that is listing more than one term, for example showing sub terms of the current term.

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

You must be logged in to reply to this topic.