Support

Account

Home Forums Add-ons Flexible Content Field Issues with taxonomy field within Flexible content

Solved

Issues with taxonomy field within Flexible content

  • Hello there,

    Having some troublesome issues with a taxonomy field within a Flexible content box. Within each layout of the flexible content there is a taxonomy where I want to grab a post category then display a list of posts from said category. I am having some strange issues where only SOME categories will display posts. It’s very inconsistent and I can’t quite work out any sort of pattern as to it’s behaviour. It seems to be mainly the sub categories which don’t display posts but of some of them do. Code below, any assistance would be GREATLY appreciated.

    <div class="row recents">
    
    <?php
     
    // check if the flexible content field has rows of data
    if( have_rows('category_feed_boxes', 50) ):
     
         // loop through the rows of data
        while ( have_rows('category_feed_boxes', 50) ) : the_row();
     
            ?>
    
    	<section class="fourcol grey-bor">
    
    <?php 
    	  $cat = get_sub_field('post_category'); 
    	  $cat_color = get_sub_field('category_text_colour'); 
    	  $cat_font = get_sub_field('category_font'); 
    	  $title_color = get_sub_field('title_text_colour'); 
    	  $title_font = get_sub_field('title_font'); 
    	  $title_font_size = get_sub_field('title_font_size'); 
    	  $excerpt_color = get_sub_field('excerpt_text_colour'); 
    ?>
    
    		<?php
    		$args = array(
    			'post_type' => 'post',
    			'posts_per_page' => '1',
    			'category_name' => $cat->name
    		);
    		$catquery = new WP_Query($args);
    		while($catquery->have_posts()) : $catquery->the_post();
    		?>
    
    		<article class="newest-article has-img" itemscope itemtype="http://schema.org/Article">
    			<a href="<?php the_permalink() ?>">
    				<h2 style="color: <?php echo $cat_color; ?>;" class="<?php echo $cat_font; ?>"><?php echo $cat->name; ?></h2>
    				<div class="bottom-content <?php if(get_sub_field('transparent_bar_cat') == "Yes"){ ?> yes-bar <?php } ?>
    				">
    					<h1 class="size-two <?php echo $title_font; ?> <?php echo $title_font_size; ?>" style="color: <?php echo $title_color; ?>;"><?php the_title(); ?></h1>
    					<p style="color: <?php echo $excerpt_color; ?>;"><?php new_excerpt(65) ;?>...</p>
    				</div>
    				<?php 
    					if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    					  the_post_thumbnail();
    					} 
    				?>
    			</a>
    		</article>
    
    	<?php endwhile; ?>
    
    		<?php
    		$args = array(
    			'post_type' => 'post',
    			'posts_per_page' => '2',
    			'category_name' => $cat->name,
    			'offset' => 1
    		);
    		$catquery = new WP_Query($args);
    		while($catquery->have_posts()) : $catquery->the_post();
    		?>
    
    		<article class="secondary snippet" itemscope itemtype="http://schema.org/Article">
    			<a href="<?php the_permalink() ?>">
    				<h2 class="size-six"><?php the_title(); ?></h2>
    				<p><?php new_excerpt(80) ;?>...</p>
    			</a>
    		</article>
    
    	<?php endwhile; ?>
    
    </section>
            <?php
     
        endwhile;
     
    else :
     
        // no layouts found
     
    endif;
     
    ?>
    </div>
  • Managed to solve the issue..

    ‘category_name’ => $cat->name

    Should have been

    ‘category_name’ => $cat->slug

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

The topic ‘Issues with taxonomy field within Flexible content’ is closed to new replies.