Support

Account

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

  • Alright.

    I think your main issue lies in the meta_key value. I sincerely hope that’s not the actual meta field name. These should only contain small letters, 0-9 and possibly _ or – for separation.

    Have a look at this and see if there’s something needing change.. look at the comments I’ve put in.

    
    <?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',
    	'orderby' => 'meta_value',
    	'meta_key' => 'weight_lbs',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category', // If you're using a custom taxonomy this needs to be changed
    			'terms' => array($part_category),
    			'field' => 'term_id'	
    		)
    		
    	}
    );
    $catquery = new WP_Query($args); 
    ?>