Come includere nome categoria / id in WP_Query per il recupero “di tipo messaggio personalizzato” da una particolare categoria?
-
16-10-2019 - |
Domanda
Ecco il codice che sto utilizzando in questo momento. Si recupera i messaggi di tutte le categorie nel tipo post '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(); ?>
voglio per visualizzare i messaggi solo da una categoria denominata 'eventcat1'. Ho provato il seguente codice, ma non ha funzionato.
<?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(); ?>
Come specificare il nome della categoria o l'id nella query? Qualsiasi aiuto sarebbe apprezzato. Grazie
Soluzione
Il seguente codice ha funzionato.
<?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(); ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange