1

I'm trying to filter the main query on the home.php template so I only shows posts from the latest issue taxonomy.

What I have so far is the below but it is still showing all the posts on the homepage. Can anyone help please?

 function uk_market_revew_latest_issue($query) {
    if ( ! is_admin() || ! is_single() ) {
         if($query->is_home() && $query->is_main_query()) {
             $issues = get_terms(array('taxonomy' => 'issue', 'hide_empty' => true));
             $ids = array();

             foreach($issues as $issue) {
                 $ids[] = $issue->slug;
             }

             $format = str_replace('issue-', '', $ids);
             $latest = max($format);

             print_r($latest);

             $tax_query = array(
                 array (
                     'taxonomy' => 'issue',
                     'field' => 'slug',
                     'terms' => 'issue-41',
                     'operator' => 'IN'
                )
            );

             $query->set('tax_query', $tax_query);

         }
     }
}

 add_action( 'pre_get_posts', 'uk_market_revew_latest_issue' );
  • remove this condition if ( ! is_admin() || ! is_single() ) {... }, see if this works – maverick Aug 24 '18 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.