WordPress.org

Ready to get started?Download WordPress

Forums

Insert custom variable in to wp_query (2 posts)

  1. lawyer01
    Member
    Posted 1 year 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',
    	'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!

  2. Sandip Patil
    Member
    Posted 1 year 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