Support

Account

Home Forums Add-ons Repeater Field Repeater shows only the id number of subfield using shortcodes

Unread

Repeater shows only the id number of subfield using shortcodes

  • Hello, I’m using this code and is working fine with almost all the fields, but i want to use a taxonomy field and i get only the id value in frontend. How I can modify this code so it shows the taxonomy value and not the id.

    function my_acf_repeater($atts, $content='') {
      extract(shortcode_atts(array(
        "field" => null,
        "sub_fields" => null,
        "post_id" => null
      ), $atts));
    
      if (empty($field) || empty($sub_fields)) {
        // silently fail? is that the best option? idk
        return "";
      }
    
      $sub_fields = explode(",", $sub_fields);
      
      $_finalContent = '';
    
      if( have_rows($field, $post_id) ):
        while ( have_rows($field, $post_id) ) : the_row();
          
          $_tmp = $content;
          foreach ($sub_fields as $sub) {
            $subValue = get_sub_field(trim($sub));
            $_tmp = str_replace("%$sub%", $subValue, $_tmp);
          }
          $_finalContent .= do_shortcode( $_tmp );
    
        endwhile;
      else :  
        $_finalContent = "$field does not have any rows";
      endif;
    
      return $_finalContent;
    }
    
    add_shortcode("acf_repeater", "my_acf_repeater");
    

    this is the code to show in frontend:

    
    [acf_repeater field="example-row" sub_fields="example-name, example-phone, example-image"]
      User: %example-name%
      Phone: %example-phone%
      profile pic: %example-image%
    [/acf_repeater]
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.