wp query - posts_per_page in a tax_query

admin2025-06-07  9

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!

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749228803a317441.html

最新回复(0)