Tax-query on taxonomy doesn´t work

I am trying to get out a custom posttypes that belongs to a specific taxonomy.
I don’t get it sorted out on taxonomy, it takes every custom post. I use this code

global $post;
$terms = get_terms(‘resmal’);
foreach ($terms as $term) :
echo get_term_link($term);
//Define the query
$args = array(
‘post_type’ => ‘resor’,
‘tax-query’ => array(
array(
‘taxonomy’ => ‘resmal’,
‘field’ => ‘slug’,
‘terms’ => ‘Italien’
)
)
);
$query = new WP_Query( $args );
// Start the Loop
if( $query->have_posts() ):
while ( $query->have_posts() ) :
$query->the_post();
echo get_the_title();
endwhile;
endif;
wp_reset_query();
wp_reset_postdata();
endforeach;

The custom posttype

function base_register_resor_post_type() {
$labels = array(
‘name’ => __( ‘Våra Resor’),
‘singular_name’ => __( ‘Resa’ ),
‘add_new’ => __(‘Skapa ny’),
‘add_new_item’ => __(‘Skapa ny Resa’),
‘edit_item’ => __(‘Redigera Resa’),
‘new_item’ => __(‘Ny Resa’),
‘view_item’ => __(‘Visa Resa’),
‘search_items’ => __(‘Sök Resa’),
‘not_found’ => __(‘Hittade inget’),
‘not_found_in_trash’ => __(‘Papperskorgen är tom!’)
);
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘has_archive’ => ‘resor’,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => array(‘slug’ => ‘resa’),
‘taxonomies’ => array(‘resmal’),
‘capability_type’ => ‘post’,
‘supports’ => array(‘title’,’editor’,’thumbnail’,’excerpt’,’revisions’),
‘show_in_nav_menus’ => true,
‘hierarchical’ => true
);
register_post_type(‘resor’, $args);
}
add_action(‘init’, ‘base_register_resor_post_type’);

The taxonomy

function base_register_destination_taxonomy() {
$labels = array(
‘name’ => ‘Resmål’,
‘singular_name’ => ‘Resmål’,
‘search_items’ => ‘Sök Resmål’,
‘all_items’ => ‘Alla Resmål’,
‘parent_item’ => ‘Parent Location’,
‘parent_item_colon’ => ‘Parent Location:’,
‘edit_item’ => ‘Ändra Resmål’,
‘update_item’ => ‘Updatera Resmål’,
‘add_new_item’ => ‘Lägg till nytt Resmål’,
‘new_item_name’ => ‘Nytt Resmål namn’,
‘menu_name’ => ‘Resmål’
);

$args = array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘has_archive’ => true,
‘rewrite’ => array( ‘slug’ => ‘resmal’ ),
‘public’ => true
);
register_taxonomy(‘resmal’, array(‘resor’), $args);
}
add_action(‘init’, ‘base_register_destination_taxonomy’);

Read more here:: Tax-query on taxonomy doesn´t work

Leave a Reply

Your email address will not be published. Required fields are marked *