• Resolved Rob

    (@robmuzo)


    Can anybody tell me how to change the query below so that it works of the term id rather than the term name?

    <?php
        query_posts(array(
            'post_type' => 'products',
    		'taxonomy' => 'category',
    		'term' => 'mytermname',
            'showposts' => 10
        ) );
        ?>

    Something like this: (Does not work)

    <?php
        query_posts(array(
            'post_type' => 'products',
    		'taxonomy' => 'category',
    		'term_id' => '57',
            'showposts' => 10
        ) );
        ?>

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Untested but this might work:

    <?php
         $args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category',
    			'field' => 'id',
    			'terms' => 57
    		)
    	)
    );
    $query = new WP_Query( $args ); ?>

    Resource: here

    Thread Starter Rob

    (@robmuzo)

    Managed to get it working with this:

    <?php $termID = get_post_meta($post->ID, 'related_category_id_meta', true); ?>
    <?php query_posts( 'post_type=products&cat='.$termID.'&posts_per_page=-1' ); ?>

    Basically I have a dropdown category selector on the custom post type category page which allows the user to select the related categories to feed under the category page

    Thread Starter Rob

    (@robmuzo)

    Resolved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress query using term id rather than name’ is closed to new replies.