Support

Account

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

  • Hi @skasprick

    Hm okay. I think you might have two different issues here:

    1. Sometimes when changing the return value you need to resave the post/term/whatever for the changes to occur. If you initially had term object you might want to try resaving.
    2. I’m fairly certain that when using the checkbox layout the return wont just be an ID integer but an array. Try this:

    
    <?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[0]),
    			'field' => 'term_id'	
    		)
    		
    	)
    );
    $catquery = new WP_Query($args); 
    ?>
    

    Or possibly:

    
    <?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[0]->term_id),
    			'field' => 'term_id'	
    		)
    		
    	)
    );
    $catquery = new WP_Query($args); 
    ?>