admin管理员组

文章数量:1130349

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!

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!

本文标签: wp querypostsperpage in a taxquery