0

I want to show two latest posts of a taxonomy in a front_page.php template.

$args_article = array(
  'post_type'             => ['text'],
  'post_status'           => ['publish'],
  'posts_per_page'        => 2,
  'tax_query'             => [
      [
        'taxonomy' => 'article-type',
        'field'    => 'slug',
        'terms'    => 'articulo',
      ]
   ]
 );
 $query_article = new WP_Query( $args_article );

It returns all posts instead two latest.

It works without tax_query:

$args_article = array(
  'post_type'             => ['text'],
  'post_status'           => ['publish'],
  'posts_per_page'        => 2,
 );
 $query_article = new WP_Query( $args_article );

The loop is very simple (it is in Blade template syntax):

@while ($query_article->have_posts()) @php $query_article->the_post() @endphp
   @include('partials.content-owl')
@endwhile

Entire code can be reached here.

And there is a provisional link with deployed site here. There are three similar loops in the front page.

How can I get just latest posts with a tax_query? Thanks!

  • can u please show me your code with loop so i will check and update if anything is going wrong. – Pratik Patel Oct 27 '18 at 9:42
  • Sure! Please, look at the updated question. – aitor Oct 27 '18 at 10:00

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.