Home Forums Front-end Issues Show Post of a Category with Taxanomy field ACF


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 :

    												// 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(); ?>
    								 <?php while ( $result->have_posts()) :$result->the_post();?>
    							<a href="<?php the_permalink(); ?>" class="function-link"><div class="function">
    										<?php if(has_post_thumbnail()){
    												} else { ?>
    													<img src="<?php bloginfo('template_url');?>/images/no-thumbnail.jpg" class="function-img">
    										<?php } ?>
    									<div class="function-content px-4">
    										<h4 class="function-title"><?php the_title();?></h4>
    										<p class="function-desc"><?php echo excerpt(35);?>...
    							<?php   endwhile; 
    									endif;  wp_reset_query();				 
  • What to you have this field set to return? Terms or IDs?

    $get_cat_id = the_sub_field('select_category');
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.