Home › Forums › Front-end Issues › Display only "Featured" custom posttypes on taxonomy page › Reply To: Display only "Featured" custom posttypes on taxonomy page
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(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.