Facebook
From Soiled Pig, 2 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 264
  1.    if($category_name !==''){
  2.      $category = array(
  3.               'taxonomy' => 'category',
  4.               'field'    => 'slug',
  5.               'terms'    => $category_name,
  6.           );
  7.    }
  8.    else {
  9.      $category = '';
  10.    }
  11.    
  12.    $args = array (
  13.       'post_type' => 'post', // it's default, you can skip it
  14.       'posts_per_page' => '1',
  15.       'order_by' => 'date', // it's also default
  16.       'order' => 'DESC', // it's also default
  17.       'tax_query' => array(
  18.           'relation' => 'AND',
  19.          
  20.           array(
  21.               'taxonomy' => 'post_tag',
  22.               'field'    => 'slug',
  23.               'terms'    => $tag_name,
  24.           ),
  25.           $category,
  26.       ),
  27.    );
  28.  
  29.    // query is made              
  30.    $query = new WP_Query( $args );