web-dev-qa-db-fra.com

Taxonomies personnalisées n'apparaissant pas dans Admin

J'ai créé un plugin d'un type de contenu personnalisé et d'une taxonomie. Le CPT se porte bien, mais pas les taxonomies. Il y a beaucoup de code, mais les informations de taxonomie sont analysées ci-dessous:

Le code complet peut être trouvé ici sur github

    <?php

function check_exhibition_type_tax() {
        $labels = array(
            'name'                  => _x( 'Exhibition Types', 'taxonomy general name' ),
            'singular_name'         => _x( 'Exhibition Type', 'taxonomy singular name' ),
            'add_new'               => _x( 'Add New Exhibition Type', 'Exhibition Type'),
            'add_new_item'          => __( 'Add New Exhibition Type' ),
            'edit_item'             => __( 'Edit Exhibition Type' ),
            'new_item'              => __( 'New Exhibition Type' ),
            'view_item'             => __( 'View Exhibition Type' ),
            'search_items'          => __( 'Search Exhibition Types' ),
            'not_found'             => __( 'No Exhibition Type found' ),
            'not_found_in_trash'    => __( 'No Exhibition Type found in Trash' ),
        );

        $pages = array('ksasexhibits');

        $args = array(
            'labels'            => $labels,
            'singular_label'    => __('Exhibiton Type'),
            'public'            => true,
            'show_ui'           => true,
            'hierarchical'      => true,
            'show_tagcloud'     => false,
            'show_in_nav_menus' => false,
            'rewrite'           => array('slug' => 'exhibiton', 'with_front' => false ),
         );
        register_taxonomy('exhibition_type', $pages, $args);
}

    add_action('init', 'register_exhibition_type_tax');

function check_exhibition_type_terms(){

    //see if we already have populated any terms
    $term = get_terms ('exhibition_type', array( 'hide_empty' => false ) );

    //if no terms then lets add our terms
      if( empty( $term ) ){
        $terms = define_exhibition_type_terms();
        foreach( $terms as $term ){
            if( !term_exists( $term['name'], 'exhibition_type' ) ){
                wp_insert_term( $term['name'], 'exhibition_type', array( 'slug' => $term['slug'] ) );
            }
        }
    }

}

add_action ( 'init', 'check_exhibition_type_terms' );

function define_exhibiton_type_terms(){

$terms = array(
        '0' => array( 'name' => 'Campus Partnerships','slug' => 'campus'),
        '1' => array( 'name' => 'Community Partnerships','slug' => 'community'),
        '2' => array( 'name' => 'Independent Study','slug' => 'independent'),
        '3' => array( 'name' => 'Digital Work.','slug' => 'digital'),
        '4' => array( 'name' => 'Mellon Foundation','slug' => 'mellon'),
    );

    return $terms;
}

add_filter( 'manage_edit-ksasexhibits_columns', 'my_ksasexhibits_columns' ) ;

function my_ksasexhibits_columns( $columns ) {

    $columns = array(
        'cb' => '<input type="checkbox" />',
        'title' => __( 'Name' ),
        'exhibitons' => __( 'Exhibiton Type' ),
        'date' => __( 'Date' ),
    );

    return $columns;
}

add_action( 'manage_studyfields_posts_custom_column', 'my_manage_ksasexhibits_columns', 10, 2 );

function my_manage_program_columns( $column, $post_id ) {
    global $post;

    switch( $column ) {

        /* If displaying the 'program_type' column. */

        case 'exhibitons' :

            /* Get the program_types for the post. */
            $terms = get_the_terms( $post_id, 'exhibition_type' );

            /* If terms were found. */
            if ( !empty( $terms ) ) {

                $out = array();

                /* Loop through each term, linking to the 'edit posts' page for the specific term. */
                foreach ( $terms as $term ) {
                    $out[] = sprintf( '<a href="%s">%s</a>',
                        esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'exhibiton_type' => $term->slug ), 'edit.php' ) ),
                        esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'exhibiton_type', 'display' ) )
                    );
                }

                /* Join the terms, separating them with a comma. */
                echo join( ', ', $out );
            }

            /* If no terms were found, output a default message. */
            else {
                _e( 'No Exhibitons Assigned' );
            }

            break;
        /* Just break out of the switch statement for everything else. */
        default :
            break;
    }
}

?>
1
timmyg

Il semblait y avoir un problème avec la façon dont vous avez enregistré la taxonomie. Je préfère enregistrer la taxonomie avant d’enregistrer le type de message. Exhibit Types

J'ai soumis une demande de tirage mais c'est parti:

<?php

// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_ksasexhibits_taxonomies', 0 );

// create two taxonomies, genres and writers for the post type "book"
function create_ksasexhibits_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
            'name'                  => _x( 'Exhibition Types', 'taxonomy general name' ),
            'singular_name'         => _x( 'Exhibition Type', 'taxonomy singular name' ),
            'add_new'               => _x( 'Add New Exhibition Type', 'Exhibition Type'),
            'add_new_item'          => __( 'Add New Exhibition Type' ),
            'edit_item'             => __( 'Edit Exhibition Type' ),
            'new_item'              => __( 'New Exhibition Type' ),
            'view_item'             => __( 'View Exhibition Type' ),
            'search_items'          => __( 'Search Exhibition Types' ),
            'not_found'             => __( 'No Exhibition Type found' ),
            'not_found_in_trash'    => __( 'No Exhibition Type found in Trash' ),
        );

        $args = array(
            'labels'            => $labels,
            'singular_label'    => __('Exhibiton Type'),
            'public'            => true,
            'show_ui'           => true,
            'hierarchical'      => true,
            'show_tagcloud'     => false,
            'show_in_nav_menus' => false,
            'rewrite'           => array('slug' => 'exhibiton', 'with_front' => false ),
         );
    register_taxonomy( 'exhibition_type', 'ksasexhibits', $args );
}

function register_ksasexhibits_posttype() {
    $labels = array(
            'name'              => _x( 'Exhibits & Programs', 'post type general name' ),
            'singular_name'     => _x( 'Exhibit', 'post type singular name' ),
            'add_new'           => __( 'Add New Exhibit & Program' ),
            'add_new_item'      => __( 'Add New Exhibit & Program' ),
            'edit_item'         => __( 'Edit Exhibit & Program' ),
            'new_item'          => __( 'New Exhibit & Program' ),
            'view_item'         => __( 'View Exhibit & Program' ),
            'search_items'      => __( 'Search Exhibit & Program' ),
            'not_found'         => __( 'No Exhibit & Program found' ),
            'not_found_in_trash'=> __( 'No Exhibit & Program found in Trash' ),
            'parent_item_colon' => __( '' ),
            'menu_name'         => __( 'Exhibits & Programs' )
        );

        //$taxonomies = array( 'exhibition_type' );

        $supports = array('title','revisions','thumbnail' );

        $post_type_args = array(
            'labels'            => $labels,
            'singular_label'    => __('Exhibit & Program'),
            'public'            => true,
            'show_ui'           => true,
            'publicly_queryable'=> true,
            'query_var'         => true,
            'capability_type'   => 'post',
            'has_archive'       => false,
            'hierarchical'      => true,
            'rewrite'           => array('slug' => 'exhibitons', 'with_front' => false ),
            'supports'          => $supports,
            'menu_position'     => 5,
            //'taxonomies'      => $taxonomies,
            'show_in_nav_menus' => true
         );
    register_post_type('ksasexhibits',$post_type_args);
}
add_action('init', 'register_ksasexhibits_posttype');

function define_exhibiton_type_terms() {
    $terms = array(
        '0' => array( 'name' => 'Campus Partnerships','slug' => 'campus'),
        '1' => array( 'name' => 'Community Partnerships','slug' => 'community'),
        '2' => array( 'name' => 'Independent Study','slug' => 'independent'),
        '3' => array( 'name' => 'Digital Work.','slug' => 'digital'),
        '4' => array( 'name' => 'Mellon Foundation','slug' => 'mellon'),
        );
    return $terms;
}

function check_exhibition_type_terms(){

    //see if we already have populated any terms
    $terms = get_terms ('exhibition_type', array( 'hide_empty' => false ) );

    //if no terms then lets add our terms
    if( empty( $terms ) ){
    $terms = array(
        '0' => array( 'name' => 'Campus Partnerships','slug' => 'campus'),
        '1' => array( 'name' => 'Community Partnerships','slug' => 'community'),
        '2' => array( 'name' => 'Independent Study','slug' => 'independent'),
        '3' => array( 'name' => 'Digital Work.','slug' => 'digital'),
        '4' => array( 'name' => 'Mellon Foundation','slug' => 'mellon'),
        );
        foreach( $terms as $term ){
            if( !term_exists( $term['name'], 'exhibition_type' ) ){
                wp_insert_term( $term['name'], 'exhibition_type', array( 'slug' => $term['slug'] ) );
            }
        }
    }

}

add_action ( 'init', 'check_exhibition_type_terms' );

?>
1
Courtney Ivey