Support

Account

Home Forums ACF PRO Display posts based on custom field within a group Reply To: Display posts based on custom field within a group

  • This solved my issue: https://code.tutsplus.com/tutorials/show-wordpress-related-posts-with-taxonomy-and-a-custom-post-type–cms-32303

    $productterms = get_the_terms( get_the_ID(), 'listing_location'  );
    
    	if( $productterms ) {	             
    	    $producttermnames[] = 0;	                     
    	    foreach( $productterms as $productterm ) {  	                 
    	        $producttermnames[] = $productterm->name;	             
    	    }	     
    	}
    
    	$args = array (
    	    'post_type' => 'post_type_listings',
    	    'tax_query' => array(
    	        array(
    	            'taxonomy' => 'listing_location',
    	            'field'    => 'slug',
    	            'terms'    => $producttermnames,
    	        ),
    	    ),
    	);
    
    	$the_query = new WP_Query( $args );
    	if( $the_query->have_posts() ): ?>
    	     
    	    <section class="product-related-posts">
    	 
    	    <?php echo '<h2>' . __( 'Related Posts', 'tutsplus' ) . '</h2>'; ?>
    	 
    	        <ul class="product-posts">
    	 
    	        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	         
    	            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	                 
    	            <?php endwhile; ?>
    	             
    	            <?php wp_reset_postdata(); ?>
    	         
    	        </ul>
    	         
    	    </section>
    	     
    	<?php endif;
    	
    };