Support

Account

Home Forums Front-end Issues Display only "Featured" custom posttypes on taxonomy page Reply To: Display only "Featured" custom posttypes on taxonomy page

  • if all you want to show on this page is the featured posts and the rest of the posts in the term will never be shown then instead of doing a custom query on the page you need to use a pre_get_posts filter and alter the query that WP is already doing.

    
    add_action('pre_get_posts', 'your_function_name_here');
    function your_function_name_here($query) {
      if (is_admin() || !$query->is_main_query()) {
        return;
      }
      if ($query->is_tax('your-taxonomy-here')) {
        $query->set('meta_key', 'uitgelicht_bij_land');
        $query->set('meta_value', '1'); 
        $query->set('posts_per_page', 3);
      }
    }
    

    If on the other hand you are showing other posts as well then you do need to do a custom query, but you need to add a tax_query. You can get the current taxonomy like

    
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    

    then you can use these values in the tax query

    
    'tax_query' => array(
      array(
        'taxonomy' => $taxonomy,
        'terms' => array($term_id)
      )
    )