¿Cómo incluir el nombre/ID de la categoría en WP_Query para recuperar el "tipo de publicación personalizado" de una categoría en particular?
-
16-10-2019 - |
Pregunta
Aquí está el código que estoy usando ahora mismo. Obtiene las publicaciones de todas las categorías en el tipo de publicación 'Sp_events'.
<?php $feat_art = new WP_Query(array('post_type' => 'sp_events','post_status' => 'publish','posts_per_page' => 1)); while($feat_art->have_posts()) : $feat_art->the_post(); ?>
Quiero mostrar las publicaciones solo de una categoría llamada 'EventCat1'. Probé el siguiente código, pero no funcionó.
<?php $feat_art = new WP_Query(array('post_type' => 'sp_events','category_name'=> 'eventcat1','post_status' => 'publish','posts_per_page' => 1)); while($feat_art->have_posts()) : $feat_art->the_post(); ?>
¿Cómo especificar el nombre de la categoría o la ID en la consulta? Cualquier ayuda sería apreciada. Gracias
Solución
El siguiente código funcionó.
<?php $feat_art = new WP_Query(array('post_type' => 'sp_events','sp_events_cat'=> 'eventcat1','post_status' => 'publish','posts_per_page' => 1)); while($feat_art->have_posts()) : $feat_art->the_post(); ?>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a wordpress.stackexchange