Thank you so much,
That worked at first try!
I do have a feeling I could have made the code more efficient. Setting variables twice?
Or is it correct right now. (it works 😉 )
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
add_action('pre_get_posts', 'uitgelichte_cursusloop_land');
function uitgelichte_cursusloop_land($query) {
if (is_admin() || !$query->is_main_query()) {
return;
}
if ($query->is_tax($taxonomy )) {
$query->set('meta_key', 'uitgelicht_bij_land');
$query->set('meta_value', '1');
$query->set('posts_per_page', 30);
}
}
// The Query
$the_query = new WP_Query(
array(
'post_type' => 'cursus',
'posts_per_page' => 30,
'meta_key' => 'uitgelicht_bij_land',
'meta_value' => '1',
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'terms' => array($term_id)
)
)
)
);
// The Loop
if ( $the_query->have_posts() ) {?>
<h3>Uitgelichte taalcursussen in <?php single_term_title(); ?></h3>
<?php while ( $the_query->have_posts() ) {
$the_query->the_post();
get_template_part( 'cursusloop', get_post_format() );
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata(); ?>