Good afternoon, I have the following problem with the query of my CPT, I want to show me the type of post, the taxonomy "courses" and the last 3 post. The query is done correctly until the taxonomy, it shows me the post of all the taxonomies (courses).
Query:
<?php
$the_query = new WP_Query( array(
'post_type' => 'circulares',
'posts_per_page' => 2,
'tax_query' => array(
'taxonomy' => 'curso',
'field' => 'slug',
'terms' => 'tercero',
),
));
while ( $the_query->have_posts() ) :
$the_query->the_post(); ?>
<?php the_title(); ?><br>
<?php endwhile;
wp_reset_postdata(); ?>
Taxonomy:
add_action( 'init', 'create_circular_taxonomies', 0 );
function create_circular_taxonomies() {
$labels = array(
'name' => _x( 'Cursos', 'taxonomy general name' ),
'singular_name' => _x( 'Curso', 'taxonomy singular name' ),
'search_items' => __( 'Buscar por Curso' ),
'all_items' => __( 'Todos los Cursos' ),
'parent_item' => __( 'Curso padre' ),
'parent_item_colon' => __( 'Curso padre:' ),
'edit_item' => __( 'Editar Curso' ),
'update_item' => __( 'Actualizar Curso' ),
'add_new_item' => __( 'Añadir nuevo Curso' ),
'new_item_name' => __( 'Nombre del nuevo Curso' ),
);
register_taxonomy( 'curso', array( 'circulares' ), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'cursos' ),
));
}
Register Post type custom:
add_action( 'init', 'circulares');
function circulares() {
$labels = array(
'name' => _x( 'Circulares', 'post type general name' ),
'singular_name' => _x( 'Circular', 'post type singular name' ),
'add_new' => _x( 'Añadir nueva', 'circular' ),
'add_new_item' => __( 'Añadir nueva circular' ),
'edit_item' => __( 'Editar circular' ),
'new_item' => __( 'Nueva circular' ),
'view_item' => __( 'Ver circular' ),
'search_item' => __( 'Buscar circulares' ),
'not_found' => __( 'No se han encontrado circulares' ),
'not_found_in_trash'=> __( 'No se ha encontrado circulares en la papelera' ),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'Circulares', $args );
}
'tax_query' => array( array( YOUR ARGUMENTS ))
and let know what happens?