Title: Help with WP Query args
Last modified: August 31, 2016

---

# Help with WP Query args

 *  Resolved [powerj](https://wordpress.org/support/users/powerj/)
 * (@powerj)
 * [10 years ago](https://wordpress.org/support/topic/help-with-wp-query-args/)
 * Hi,
    Hoping someone can help me with this loop. It works if a term is set. And
   if I manually change the $arg ‘tax_query’ => ” it works. But it shows no results
   as it is – I just don’t get it!
 *     ```
       function news_archive_loop() {
           global $post;
           $term = get_query_var(term);
            if (isset($term))
           {
               $tax_query[] =  array(
                       'taxonomy' => 'news-states',
                       'field' => 'name',
                       'terms' => $term
                   );
           } else {
                       $tax_query =  '';
            }
   
          $args = array(
       		'post_type'      => 'news-article',
       		'posts_per_page' => 12,
       		'post_status'    => 'publish',
       		'paged'          => get_query_var( 'paged' ),
               'tax_query' => $tax_query
   
           );
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Ravikumar Patel](https://wordpress.org/support/users/ravipatel/)
 * (@ravipatel)
 * [10 years ago](https://wordpress.org/support/topic/help-with-wp-query-args/#post-7293415)
 * Discribe more info and use this short code.
 * on $term single value arrived? if more then one pass with comma in array.
    `'
   terms' => array('zyf','dasd');`
 *     ```
       <?php
       function news_archive_loop() {
           global $post;
           $term = get_query_var(term);
           $args = array(
       		'post_type'      => 'news-article',
       		'posts_per_page' => 12,
       		'post_status'    => 'publish',
       		'paged'          => get_query_var( 'paged' ),
       		if (isset($term)){
       			'tax_query' => array(
       			array(
       					'taxonomy' => 'news-states',
       					'field' => 'name',
       					'terms' => $term
       				),
       			);
       		}
           );
       }
       ```
   
 *  Thread Starter [powerj](https://wordpress.org/support/users/powerj/)
 * (@powerj)
 * [10 years ago](https://wordpress.org/support/topic/help-with-wp-query-args/#post-7293554)
 * This returns unexpected if error.
 *  [swayam.tejwani](https://wordpress.org/support/users/swayamtejwani/)
 * (@swayamtejwani)
 * [10 years ago](https://wordpress.org/support/topic/help-with-wp-query-args/#post-7293611)
 * try this code below
 *     ```
       function news_archive_loop() {
           global $post;
           $term = get_query_var(term);
   
          $args = array(
       		'post_type'      => 'news-article',
       		'posts_per_page' => 12,
       		'post_status'    => 'publish',
       		'paged'          => get_query_var( 'paged' ),
               'tax_query' => $tax_query
   
           );
       	  if (isset($term))
           {
       		$args['tax_query'] = array(
                       'taxonomy' => 'news-states',
                       'field' => 'name',
                       'terms' => $term
                   );
           }
       ```
   
 * let me know if it works ?
 *  Thread Starter [powerj](https://wordpress.org/support/users/powerj/)
 * (@powerj)
 * [10 years ago](https://wordpress.org/support/topic/help-with-wp-query-args/#post-7293623)
 * many thanks

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Help with WP Query args’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [powerj](https://wordpress.org/support/users/powerj/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/help-with-wp-query-args/#post-7293623)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
