Support » Plugins and Hacks » Hacks » 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)
  • 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.