Support

Account

Home Forums ACF PRO Getting ACF field from a taxonomy in a page with WP_query Reply To: Getting ACF field from a taxonomy in a page with WP_query

  • I finally found out the solution. I was wrong from the start. This code works for me, it can probably be optimized

    <?php
    	$args = array(
    		'taxonomy' => 'marques-produits',
    	    'orderby' => 'name',
    	    'order'   => 'ASC'
    	    );	
    	   $cats = get_categories($args);
    	   foreach($cats as $cat) {
    		   
    		   if ($logo = get_field('logo_marque','marques-produits_'.$cat->term_id)) {
    			   $cats_keep[] = $cat;
    			   }
    			}
    			foreach($cats_keep as $cat) {
    		   
    	?>
    	      <a href="<?php echo get_category_link( $cat->term_id ) ?>">
    	           <img src="<?php echo esc_url($logo['url']); ?>" alt="<?php echo esc_attr($logo['alt']); ?>" />
    	      </a>
    	<?php
    	   }
    	?>