etichete și categorii pentru tipuri personalizate de postări
18 ian. 2011, 00:07:27
Vizualizări: 18.7K
Voturi: 1
Ce trebuie să fac pentru a activa categorii și etichete pentru un tip personalizat de postare pe care l-am creat? Folosesc următorul cod:
/* Crează un tip personalizat de postare: "Tilbud" */
register_post_type('tilbud', array(
'label' => __('Tilbud'),
'singular_label' => __('Tilbud'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'supports' => array('title')
));

User
100
Toate răspunsurile la întrebare
4
3
schimbă codul tău în acesta:
/* Creează un tip personalizat de postare: "Tilbud" */
register_post_type('tilbud', array(
'label' => __('Tilbud'),
'singular_label' => __('Tilbud'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'taxonomies' => array('post_tag','category'),
'supports' => array('title')
));
funcția register_post_type primește un nume pentru tipul de postare și un array de argumente una dintre acestea este "taxonomies" și aceasta este ceea ce îți lipsește.

Bainternet
67.7K
18 ian. 2011 00:52:47
1
Dacă ai nevoie să afișezi etichete (tags) pentru un tip personalizat de postare (custom post type) - iată un exemplu bun https://jamper.online/afisare-etichete-tags-pentru-postari-personalizate-custom-post-type
function get_terms_by_custom_post_type( $post_type, $taxonomy ){
$args = array( 'post_type' => $post_type);
$loop = new WP_Query( $args );
$postids = array();
// construiește un array cu ID-urile postărilor
while ( $loop->have_posts() ) : $loop->the_post();
array_push($postids, get_the_ID());
endwhile;
// obține valorile taxonomiei bazate pe array-ul de ID-uri
$taxonomies = wp_get_object_terms( $postids, $taxonomy );
wp_reset_postdata();
return $taxonomies;
}

Platon
11
15 sept. 2023 12:57:50
Întrebări similare
2
răspunsuri
1
răspunsuri