archivio dei tag della tassonomia per un custom post type: nessun post trovato
28 lug 2013, 03:35:54
Visualizzazioni: 8.06K
Voti: 8
Ho registrato un custom post type "object" e ho registrato la tassonomia "post_tag" in modo che questi oggetti possano essere taggati.
register_taxonomy_for_object_type('post_tag', 'object');
Quando visito domain.com/tag/{object-slug}
non trova alcun post, nonostante ci siano.
Ecco come ho dichiarato il mio CPT:
register_post_type( 'objet',
array('labels' => array(/* rimosso per chiarezza */),
'description' => __( 'blabla' ),
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'menu_position' => 3,
'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png',
'rewrite' => array( 'slug' => 'stock', 'with_front' => false ),
'has_archive' => 'stock',
'capability_type' => 'post',
'taxonomies' => array('post_tag'),
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'sticky')
)
);

pixeline
2.88K
Commenti
Tutte le risposte alla domanda
1
2
Le query degli archivi per tag e categorie per impostazione predefinita cercano solo il tipo di post post
. Per aggiungere il tuo tipo di post personalizzato a queste query, puoi usare l'azione pre_get_posts
:
function wpa_cpt_tags( $query ) {
if ( $query->is_tag() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'object' ) );
}
}
add_action( 'pre_get_posts', 'wpa_cpt_tags' );

Milo
78.9K
28 lug 2013 03:51:47
Commenti
Grazie. E per includere anche le categorie nella stessa funzione, come necessario, la condizione dovrebbe essere if( ($query->is_tag() || $query->is_category()) && $query->is_main_query() ){}

6 ott 2016 19:44:49
Domande correlate