Support

Account

Home Forums ACF PRO Repeater Field Broken when using category.php file…

Solved

Repeater Field Broken when using category.php file…

  • I’m trying to access a repeater field from a category.php page. Other field types return the data as expected, and the same code used in a template page returns the repeater field as expected. Any thoughts?
    Here’s the code

    
    <?php if ( have_posts() ): ?>
    <h2><!--Category Archive:--> <?php echo single_cat_title( '', false ); ?></h2>
    <?php while ( have_posts() ) : the_post(); ?>
    
    <?php // check if the repeater field has rows of data ?>
     <?php if( have_rows('display_title') ): ?>
         <?php // loop through the rows of data ?>
         <h2>
             <a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark">
             <?php while ( have_rows('display_title') ) : the_row(); ?>
             <?php // display a sub field value ?>
             <span class="<?php echo get_sub_field('font_choice', 'option') ?>"><?php the_sub_field('text_section'); ?></span>
             <?php endwhile; ?>
             </a>
          </h2>
    <?php else : ?>
        <?php // no rows found ?>
            <h2><a href="<?php esc_url( the_permalink() ); ?>" title="link to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <?php endif; ?>
    
    <?php endwhile; ?>
    <?php else: ?>
    <h2>No posts to display in <?php echo single_cat_title( '', false ); ?></h2>
    <?php endif; ?>
    
  • Ok, finally got it sorted…
    For anyone else out there that might run into this problem here’s the solution.
    Just add the following to your functions.php file.

    
    //Include CPT In Categories Pages
    function namespace_add_custom_types( $query ) {
        if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
            $post_types = get_post_types( '', 'names' ); 
            $query->set( 'post_type', $post_types);
            return $query;
        }
    }
    add_filter( 'pre_get_posts', 'namespace_add_custom_types');
    
  • Thank you for this post!
    Had the same issue today.

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

The topic ‘Repeater Field Broken when using category.php file…’ is closed to new replies.