So, I need to echo the URL of a custom field from the last post published in a certain post type and with a particular taxonomy.
This code so far works OK, but even that numberposts = 1
, $imagecurrent
will contain the image URL from all the posts matching the conditions, not only the last one.
<?php
$args = array(
'numberposts' =>'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(); ?>
What am I missing?
EDIT
I have included the code from the solution (posts_per_page), but it's still spitting out the URL from all posts, not only the last one.