Home Forums General Issues Repeater field on taxonomy help

Repeater field on taxonomy help

  • Hi there – not sure if I am in the right place for this but I am having a similar sort of problem.

    I am successfully displaying my custom fields in my custom taxonomy.php file using the below code

    <?php $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); ?>
    <img src="<?php $logo = get_field('logo',  $term->taxonomy.'_'.$term->term_id);
    	echo $logo; ?>" class="company-logo" />

    So I tried this approach for my repeater fields but no luck.

    <?php if ($wpr = get_field('white_paper_repeater',  $term->taxonomy.'_'.$term->term_id)); 
    echo $wpr; ?>
    	<?php while(has_sub_field('white_paper_repeater,  $term->taxonomy.'_'.$term->term_id')): ?>
    		<p><?php the_sub_field('title1,  $term->taxonomy.'_'.$term->term_id'); ?><br><?php the_sub_field('content2,  $term->taxonomy.'_'.$term->term_id'); ?></p>
    	<?php endwhile; ?>
    <?php endif; ?>

    Can anyone shed some light on this and see where I have gone wrong? I tried the repeater code like that but it broke the page, but just using the standard code didn’t break the page. But nothing loaded.

    All help appreciated.


  • Hi @shrimp144

    I have moved this reply into it’s own topic as it was not a continuation of the previous topic.

    I’m not sure exactly what the issue is here, but I’ll take a guess that it is:
    the_sub_field('title1, $term->taxonomy.'_'.$term->term_id');

    The the_sub_field functions only have 1 parameter, not 2.

    Double check the docs again to see if you have missed anything else, and give it another go.

    Also, echo $wpr; wont work because it is an array. Use a var_dump function instead to print an array


  • Hi – thanks for getting back to me.

    Found the original issue, it was a ; instead of a :

    But anyway, went back to docs and this is what I am now using.

    	// vars
    	$queried_object = get_queried_object(); 
    	$taxonomy = $queried_object->taxonomy;
    	$term_id = $queried_object->term_id;  
    	// load content for this taxonomy term
    	$docs = get_field('docs', $taxonomy . '_' . $term_id);
    <?php if($docs = get_field('docs')): ?>
    	<?php while($docs = has_sub_field('docs')): ?>
    		<p><?php the_sub_field('doc_title'); echo $docs; ?><br>
    		<?php the_sub_field('doc_file'); ?></p>
    	<?php endwhile; ?>
    <?php endif; ?>

    This works, as in, when using var_dump I can see the output. But it’s only the string.

    Can’t seem to get it to display in the repeater code.

    Any ideas?


    //EDIT – The repeater group is called docs. The sub fields are doc_title and doc_file

  • Hi @shrimp144

    The issue is that your if statement will never return true, but is also a bit odd.
    if($docs = get_field('docs')):

    This should juse be:


    Using get_field(‘docs’) wont work, becuase you need to add the $post_id param. You have done this in the 1st half of your code, but then you forget to add it into your if statement.

    That said, it doesn’t need to be in your if statement at all.


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

The topic ‘Repeater field on taxonomy help’ is closed to new replies.