Site icon Hip-Hop Website Design and Development

The most recent post of custom taxonomy

I am trying to get the most recent post of the taxonomy term ‘featured-layout’ within the taxonomy ‘value_category’. The following code is returning all the ‘featured-layouts’ when I’m only wanting to return the most recent:

<?php

$cat_arr = array(
  'test-1',
  'test-2',
  'test-3',
);

$args = array(
  'post_type' => 'values',
  'posts_per_page' => 1,
);

$mobile_posts = get_posts($args);
$count = 0;

foreach ($mobile_posts as $mobile_post) : setup_postdata($mobile_post);

  //Getting 'Featured' Value
  $featured_value_cat_query = new WP_Query( array (
    'post_type' => 'values',
    'posts_per_page' => -1,
    'tax_query' => array(
      'relation' => 'AND',
        array(
          'taxonomy'   => 'value_layout_position',
          'field'      => 'slug',
          'terms'      => 'featured-layout',
        ),
        array(
          'taxonomy' => 'value_category',
          'field'    => 'slug',
          'terms'    => $cat_arr,
        ),
    ),
  ) );

  if ( $featured_value_cat_query->have_posts() ) {

    while ( $featured_value_cat_query->have_posts() ): $featured_value_cat_query->the_post();

      echo ' | ' . the_title();

    endwhile;

  }

endforeach;

wp_reset_postdata();

?>

Does anyone know how to only return the most recent post from the ‘featured-layout’ term? Thanks!