Title: Insert custom variable in to wp_query
Last modified: August 20, 2016

---

# Insert custom variable in to wp_query

 *  [lawyer01](https://wordpress.org/support/users/lawyer01/)
 * (@lawyer01)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-variable-in-to-wp_query/)
 * Im trying to query custom post type by category_name which is a custom field.
   So im trying to insert the value of that custom field in to array via varriable
   but the variable inside the query is for some reason empty. My code looks like
   this:
 *     ```
       <?php $currentCat = the_field('slider_cat'); ?>
   
       <?php $loop = new WP_Query( array(
       	'orderby' => 'desc',
       	'taxonomy'=>'category',
       	'term' => $currentCat,
       	'post_type' => 'news',
       	'posts_per_page' => 50
       ) ); ?>
       <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
   
          <div class="post">
          </div>
   
       <?php endwhile; ?>
       ```
   
 * Any help is appriciated!

Viewing 1 replies (of 1 total)

 *  [Sandip Patil](https://wordpress.org/support/users/sandipp/)
 * (@sandipp)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-variable-in-to-wp_query/#post-3137320)
 * Veryfy that you are getting category ID in var $currentCat OR use below line:
 * $currentCat = get_query_var(‘cat’);

Viewing 1 replies (of 1 total)

The topic ‘Insert custom variable in to wp_query’ is closed to new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Sandip Patil](https://wordpress.org/support/users/sandipp/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-variable-in-to-wp_query/#post-3137320)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
