Home Forums General Issues Query posts via Taxonomy field Reply To: Query posts via Taxonomy field

  • Hi,
    i have a similar problem:

    I have a custom post type with different taxonomies.

    I want to check for a custom field within a site, which holds the taxonomy name from the custom posts. So i can enter the taxonomy in an ACF field on top of each site, and the loop should output all posts within that taxonomy i’ve entered. But it seems not to work, and my coding skills are poor…

    “kategorie_eintragen” is my taxonomy ACF field for the sites, i’ve added these taxonomies before within my custom post type “touren”.

    Here my code from the page template:

    					<div class="videos">
    						// get posts
    						$kategorie = get_field('kategorie_eintragen');
    						$posts = get_posts(array(
    							'post_type'			=> 'touren',
    							'posts_per_page'	=> -1,
    							'post_status' 		=> 'publish',
    							'orderby' 			=> 'date',
    							'order'				=> 'ASC',
    							'tax_query' => array(
    									'taxonomy' => 'kategorie_eintragen',
    									'terms' => $kategorie,
    						if( $posts ): ?>
    							<?php foreach( $posts as $post ): 
    								setup_postdata( $post ) ?>
    								<article id="post-<?php the_ID(); ?>" class="post-<?php the_ID(); ?> post type-post status-publish format-standard">
    								<a href="<?php the_field('link_zur_tour'); ?>">
    								<div class="videos-title aktiv-bild">
    									$image = get_field('bild_der_tour');
    									$size = 'oberkategorien'; // (thumbnail, medium, large, full or custom size)
    									if( $image ) {
    										echo wp_get_attachment_image( $image, $size );
    									} ?>
    									<h2><?php the_field('titel_der_tour'); ?></h2>
    							<?php endforeach; ?>
    							<?php wp_reset_postdata(); ?>
    						<?php endif; ?>		

    How do i make the loop query these custom post types only within the taxonomy i gave him on the current site?