显示特定分类&帖子类型的最后一篇帖子中自定义字段的URL

时间:2016-06-27 作者:Eric Mitjans

因此,我需要从last post published 在特定的帖子类型和特定的分类中。

到目前为止,这段代码工作正常,但即使如此numberposts = 1, $imagecurrent 将包含图像URLfrom all the posts 符合条件,not only the last one.

<?php 
    $args = array(
        \'posts_per_page\'=> 1,
        \'post_type\'     => \'exhibition\',
        \'tax_query\' => array(
        array(
          \'taxonomy\' => \'exhibitions\',
          \'field\' => \'id\',
          \'terms\' => 720, // Where term_id of Term 1 is "1".
        )),
    );

    $the_query = new WP_Query( $args );

?>
<?php if( $the_query->have_posts() ): ?>
    <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <?php echo $imagecurrent = get_field(\'exhibition_menu_image\');
    ?>
    <?php endwhile; ?>
<?php endif; ?>

<?php wp_reset_query(); ?>
我错过了什么?

EDIT

我已经包含了解决方案中的代码(posts\\u per\\u page),但它仍然会从所有帖子中弹出URL,而不仅仅是最后一篇。

1 个回复
最合适的回答,由SO网友:mmm 整理而成

numberposts 不存在用于WP_Query 而是使用

"posts_per_page" => 1

相关推荐

如何在wp-Query中比较不同的时间戳以获取事件自定义帖子类型?

我有一个带有自定义元数据库的自定义帖子类型(as seen on wptheming.com) 并且希望进行查询以显示即将发生的事件,例如在侧边栏中,过去的日期被忽略。但我需要一个当前时间的值来和事件开始时间进行比较。现在我从current_time(\'mysql\') 看起来是这样的:2012-02-16 13:15:31元的开始时间如下所示:201108121100如何使这两个日期具有可比性?我可以在查询中执行吗?或者是否有其他解决方案?以下是我到目前为止的查询(值留空,时间戳回显):<?ph