Aggiungi tag al tipo di post personalizzato
-
29-09-2020 - |
Domanda
Sto usando il quadro di ciliegio su un sito WP.Viene fornito con un tipo di post personalizzato che può essere utilizzato per aggiungere "membri del team" e creare pagine del personale ecc.
Ho bisogno di espandere questo in modo che io possa aggiungere tag a ciascun "membro del team" in Orient che posso essenzialmente taggarli come lavorare in un reparto A / B / c / ecc.
Il tipo di post personalizzato è registrato nel file tema-init.php utilizzando questo codice;
/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
)
)
);
}
add_action('init', 'my_post_type_team');
.
Voglio aggiungere tag a questo, in modo che quando aggiungo un nuovo membro del team, posso anche assegnarli a un dipartimento per aggiungere un dato tag pertinente.Attualmente la casella dell'editor di tag non viene visualizzata sulla pagina Aggiungi nuova / edit.
Quindi, ho adattato il codice sopra per includere una tassonomia del registro come questa;
/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
)
)
);
register_taxonomy(
'team_tag',
'team',
array(
'hierarchical' => false,
'label' => theme_locals("tags"),
'singular_name' => theme_locals("tag"),
'rewrite' => true,
'query_var' => true
)
);
}
add_action('init', 'my_post_type_team');
.
Tuttavia, non sto ancora ottenere la casella di tag che si presenta sulla pagina Modifica in Admin.
Qualsiasi aiuto con questo sarà molto apprezzato.
Soluzione
Sembra che il problema sia stato a parte il loro essere un tema-init.php nel tema figlio che stava sovrascrivendo parti del tema-init.php nel tema quadro genitore / ciliegio.
Ho risolto il problema aggiungendo il seguente codice nel tema-init.php;
register_taxonomy('team_tag', 'team', array(
'hierarchical' => false,
'label' => theme_locals("tags"),
'singular_name' => theme_locals("tag"),
'rewrite' => true,
'query_var' => true
)
);
. Altri suggerimenti
Prova questo
register_taxonomy(
'team_tag',
'team',
array(
'hierarchical' => false,
'label' => __( 'Tags', CURRENT_THEME ),
'singular_name' => __( 'Tag', CURRENT_THEME ),
'rewrite' => true,
'query_var' => true
)
);
. register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
),
'taxonomies' => array('team_tag')
)
);
.
Puoi vedere che ho aggiunto il parametro taxonomies
alla funzione register_post_type
.
Sebbene questo codice dovrebbe funzionare, è possibile provare a creare la relazione in seguito, con questo:
add_action('init', 'add_tax_post_rel');
function add_tax_post_rel() {
register_taxonomy_for_object_type('team_tag', 'team', 11);
}
. Puoi provare questo
add_action( 'init', 'create_client_tax' );
function create_client_tax() {
register_taxonomy(
'client_tag', //your tags taxonomy
'client', // Your post type
array(
'hierarchical' => false,
'label' => __( 'Tags', CURRENT_THEME ),
'singular_name' => __( 'Tag', CURRENT_THEME ),
'rewrite' => true,
'query_var' => true
)
);
}
.
potrebbe essere questo ti aiuterà