Support

Account

Home Forums General Issues Insert Cat ID into Query Reply To: Insert Cat ID into Query

  • Great!

    The below Solved my problem! Just one note, I had to change the last curly bracket to a bracket just above the Wp_Query. Not having a matching meta_key tripped me up for just a minute too, but temporarily eliminating the reordering proved the code is good! Thanks! This helps some of us continue to make a living! 🙂

    The winning code:

    <?php
    $part_category = get_sub_field('part_category'); // This HAS to be a string value. Make sure that it's not an array or term object.
    $args = array(
    	'post_type' => 'sweeps',
    	'posts_per_page' => -1, //fetches ALL posts without limit
    	'order' => 'ASC',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category', // If you're using a custom taxonomy this needs to be changed
    			'terms' => array($part_category[0]),
    			'field' => 'term_id'	
    		)
    		
    	)
    );
    $catquery = new WP_Query($args); 
    ?>