• Hey all,

    I’d like to run a query to find posts that have certain terms across more than one taxonomy –

    i.e. tax-one = ’10’, tax-two = ’20’ and tax-three = ’30’. I was looking at a custom query but I’m not sure how to write this – does anybody know of a way of doing it with query posts?

    If a custom query is the way I must go, then here is what I have so far –

    $terms = "$wpdb->terms.term_id = ".join($filters, " AND $wpdb->terms.term_id = ");
    
    $query = "
    	SELECT *
    	FROM $wpdb->posts
    	LEFT JOIN $wpdb->term_relationships ON ( $wpdb->posts.ID = $wpdb->term_relationships.object_id )
    	LEFT JOIN $wpdb->term_taxonomy ON ( $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id )
    	LEFT JOIN $wpdb->terms ON ( $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id )
    	WHERE $wpdb->posts.post_type = '".POST_TYPE_STAFF."'
    	AND $wpdb->posts.post_status = 'publish'
    	AND $terms;
    ";

    Any help here is greatly appriciated.

    Thanks

  • The topic ‘Help with custom query’ is closed to new replies.