Home › Forums › Front-end Issues › Show Post of a Category with Taxanomy field ACF
hi
I want to get the ID of a category from the taxonomy field and display its contents based on the following code, but in output only that number is printed and the posts
I want the category ID I specified to be stored in the $get_cat_id variable and be in the array entered :
<?php
// Check rows exists.
if( have_rows('functions_tabs') ):
$counter = -1;
$count = 0;
// Loop through rows.
while( have_rows('functions_tabs') ) : the_row();
$term_id = 92;
$counter++ ;
$get_cat_id = the_sub_field('select_category');
?>
<div class="tab-pane fade <?php if (!$count) {?> show active <?php }?>" id="v-pills-<?php echo $counter;?>">
<?php $args= array('post_type' => 'products',
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'DESC',
'tax_query' => array( array( 'taxonomy' => 'categories',
'field' => 'id',
'terms' => array($get_cat_id) ) ) );
$result = new WP_Query( $args ); if ( $result->have_posts()):?>
<div class="function-top p-4">
<h3><?php the_sub_field('name_tab_functions'); ?></h3>
<p class="m-0"><?php echo category_description(); ?>
</div>
<?php while ( $result->have_posts()) :$result->the_post();?>
<a href="<?php the_permalink(); ?>" class="function-link"><div class="function">
<div>
<?php if(has_post_thumbnail()){
the_post_thumbnail('thumb300170',array('alt'=>''.get_the_title(),'class'=>'function-img','title'=>''.get_the_title().''));
} else { ?>
<img src="<?php bloginfo('template_url');?>/images/no-thumbnail.jpg" class="function-img">
<?php } ?>
</div>
<div class="function-content px-4">
<h4 class="function-title"><?php the_title();?></h4>
<p class="function-desc"><?php echo excerpt(35);?>...
</div>
</div></a>
<?php endwhile;
endif; wp_reset_query();
?>
</div>
<?php
$count++;
endwhile;
endif;
?>
What to you have this field set to return? Terms or IDs?
$get_cat_id = the_sub_field('select_category');
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.