query_posts by category_name and custom taxonomy

I want to display posts filtered by category_name and custom taxonomy-term:

I have

function channel_init() {
// create a new taxonomy
register_taxonomy(
    'channel',
    'post',
    array(
        'label' => __( 'Channel' ),
        'rewrite' => array( 'slug' => 'channel' ),
        'hierarchical' => true,
        'capabilities' => array(
            'manage__terms' => 'edit_posts',
            'edit_terms' => 'manage_categories',
            'delete_terms' => 'manage_categories',
            'assign_terms' => 'edit_posts'
        )
    )
);

}
add_action( 'init', 'channel_init' );

Imagine i have a channel-term “news”. And a catgory_name “music” – Now i want to query:

query_posts( array( 'channel' => 'news', 'category_name' => 'music') );

channel is ignored category is filtered only.

Solutions Collecting From Web of "query_posts by category_name and custom taxonomy"

$args = array(
'post_type' => 'post',
'tax_query' => array(
    'relation' => 'AND',
    array(
        'taxonomy' => 'channel',
        'field'    => 'slug',
        'terms'    => array( 'news', 'comedy' ), //this is by slug
    ),
    array(
        'taxonomy' => 'category',
        'field'    => 'term_id',
        'terms'    => array( 103, 115, 206 ), //this is by id
    ),
),

);

$query = new WP_Query( $args );

That could be great if you use WP_Query than query_posts. But result are the same. WP_Query is more flexible :). Don’t forget to check more in deep about query.