Home › Forums › Add-ons › Flexible Content Field › 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
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.