我无法将最后一篇文章添加为特色

问题描述 投票:0回答:1

我有以下查询,显示 1 篇具有特色标签的帖子,效果很好,但如果我想保留另一个特色,我必须停用第一个,我该怎么做才能只添加最后一个特色,而不停用之前的? (它们通过检查字段激活)

<?php
global $post;

$array_terms    = [];
$term_destacado = 'destacado';
$data           = [
    'taxonomy' => 'post_tag',
    'field'    => 'slug',
    'terms'    => $term_destacado,
];
array_push( $array_terms, $data );

$myposts = get_posts( [
    'posts_per_page' => 1,
    'offset'         => 0,
    'post_type'      => 'podcast',
    'tax_query'      => ['relation' => 'AND', $array_terms],

] );
if ( $myposts ) {
    foreach ( $myposts as $post ) :
        setup_postdata( $post ); ?>
php wordpress
1个回答
1
投票

您可以将查询更改为按修改日期排序,因为您想要精选的新帖子将是最新/最近保存的帖子。

您可以在您的查询中添加:

'order' => 'modified'

将其添加到

$my_posts
数组中:

$myposts = get_posts( [
    'posts_per_page' => 1,
    'offset'         => 0,
    'post_type'      => 'podcast',
    /* ADDED HERE */
    'order'          => 'modified',
    'tax_query'      => ['relation' => 'AND', $array_terms],

] );
© www.soinside.com 2019 - 2024. All rights reserved.