Insert custom variable in to wp_query (2 posts)

  1. lawyer01
    Posted 3 years ago #

    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',
    	'term' => $currentCat,
    	'post_type' => 'news',
    	'posts_per_page' => 50
    ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       <div class="post">
    <?php endwhile; ?>

    Any help is appriciated!

  2. Sandip Patil
    Posted 3 years ago #

    Veryfy that you are getting category ID in var $currentCat OR use below line:

    $currentCat = get_query_var('cat');

Topic Closed

This topic has been closed to new replies.

About this Topic