Support

Account

Home Forums ACF PRO Acf front end for Repeater which has taxonomy as subfield

Solving

Acf front end for Repeater which has taxonomy as subfield

  • Hi,

    I have field group with repeater which in turn have 3 sub fields.
    1. Product category—- which is taxonomy
    2. Product——which is post object
    2. Activity—– which is another taxonomy

    How to show these data in front end. The following code returns ID of product category when we set return type as term id. But when we set it as term object there is no result. Can someone guide me on this

    <?php
    // check if the repeater field has rows of data
    if( have_rows(‘product_details’) ):
    // loop through the rows of data
    while ( have_rows(‘product_details’) ) : the_row();
    // display a sub field value
    the_sub_field(‘product_category’);
    endwhile;
    else :
    // no rows found
    endif;
    ?>

  • Hi @madhan2085

    I’m afraid the the_sub_field() function is not an appropriate function to use with the taxonomy field. Kindly use the get_sub_field() function like this instead:

    $the_product_cat = get_sub_field(‘product_category’);
    print_r($the_product_cat);

    These pages should give you more idea about it: https://www.advancedcustomfields.com/resources/taxonomy/, https://www.advancedcustomfields.com/resources/get_sub_field/.

    I hope this helps 🙂

  • Hi James,

    The above code returned NULL.

  • Hi @madhan2085

    That’s weird. Could you please debug the repeater like this:

    var_dump( get_field('product_details') );

    If that doesn’t work, could you please provide the product ID like this:

    var_dump( get_field('product_details', 99) );

    Where ’99’ is product ID.

    Also, could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Sixteen) with other plugins deactivated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.

    If still no joy, could you please share the JSON export file of your field group so I can test it out on my installation?

    Thanks 🙂

  • Hi i have attached the json file. Still no output.

  • Hi @madhan2085

    It seems that you use the repeater in the “job listing” post type. In this case, you need to pass the job listing ID instead of the product ID. If that doesn’t work, could you please try the following code?

    global $post;
    var_dump( get_field('product_details', $post->ID) );

    Also, don’t forget to change the “Return Value” to “Term Object”.

    If still no joy, could you please open a new ticket and provide temporary admin credentials to your site? You can open a new ticket here: https://support.advancedcustomfields.com/new-ticket. Also, please don’t forget to explain the issue again and provide the link to this thread.

    Thanks 🙂

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

The topic ‘Acf front end for Repeater which has taxonomy as subfield’ is closed to new replies.