yanknudtskov
11/25/2014 - 8:28 PM

How to get categories from a taxonomy field with Advanced Custom Fields

How to get categories from a taxonomy field with Advanced Custom Fields

<?php if(get_field('category')) : ?>

	<?php

		$categories = get_field('category');

		$args = array(
			'sort_order' => 'DESC',
			'sort_column' => 'post_date',
			'tax_query' => array(
		        array(
		        'taxonomy' => 'referencer_kategorier',
		        'field' => 'term_id',
		        'terms' => $categories)
		    ),
			'post_type' => 'reference',
			'post_status' => 'publish',
			'posts_per_page' => 100,
			//'paged'	=> $paged
		); 

		$category_posts = get_posts($args);

	?>

	<?php if($category_posts != null) : ?>

	<?php global $post; ?>

	<div class="row">

		<?php foreach( $category_posts as $post ) : setup_postdata( $post ); ?>

			<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 blog-excerpt">
				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>"><?php the_post_thumbnail( 'one-fourth', array('class' => 'feature-image') ); ?></a>
			</div>

			<div class="col-xs-12 col-sm-6 col-md-8 col-lg-8 blog-excerpt">

				<h2 class="list-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
				<p><?php the_excerpt(); ?></p>
				<a href="<?php the_permalink(); ?>" title="<?php _e('Læs mere', 'custom_theme'); ?>"><?php _e('Læs mere', 'custom_theme'); ?></a></p>

			</div>

		<?php endforeach; wp_reset_postdata(); ?>

	</div>


	<?php endif; ?>

<?php endif; ?>