因此,我需要从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,而不仅仅是最后一篇。