admin管理员组

文章数量:1130349

I'm very new to WordPress, but I've created a custom post type with two sets of tags. I've added the tags by using the following code:

/**
 * custom tags
 */
function gccsi_create_client_tax() {

    /* Teams */
    register_taxonomy( 
        'post_team', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Teams', CURRENT_THEME ), 
            'singular_name' => __( 'Team', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

    /* Locations */
    register_taxonomy( 
        'post_location', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Locations', CURRENT_THEME ), 
            'singular_name' => __( 'Location', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

}
add_action( 'admin_init', 'gccsi_create_client_tax' );

Which seems to work fine, I'm trying to now display those tags on the main page (which displays all items) so people can filter the listing page. I've tried the following:

$tagsTeam   = get_terms( 'post_team' ); ## I also tried get_terms( 'team' );
echo '<pre>';print_r($tags);echo '</pre>';

Which gives me this:

WP_Error Object
(
    [errors] => Array
        (
            [invalid_taxonomy] => Array
                (
                    [0] => Invalid taxonomy.
                )

        )

    [error_data] => Array
        (
        )

)

I've also tried using:

the_tags();

But that doesn't display anything. I've searched but I can't seem to find anything else that doesn't need the ID?

Any help would be appreciated!

I'm very new to WordPress, but I've created a custom post type with two sets of tags. I've added the tags by using the following code:

/**
 * custom tags
 */
function gccsi_create_client_tax() {

    /* Teams */
    register_taxonomy( 
        'post_team', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Teams', CURRENT_THEME ), 
            'singular_name' => __( 'Team', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

    /* Locations */
    register_taxonomy( 
        'post_location', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Locations', CURRENT_THEME ), 
            'singular_name' => __( 'Location', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

}
add_action( 'admin_init', 'gccsi_create_client_tax' );

Which seems to work fine, I'm trying to now display those tags on the main page (which displays all items) so people can filter the listing page. I've tried the following:

$tagsTeam   = get_terms( 'post_team' ); ## I also tried get_terms( 'team' );
echo '<pre>';print_r($tags);echo '</pre>';

Which gives me this:

WP_Error Object
(
    [errors] => Array
        (
            [invalid_taxonomy] => Array
                (
                    [0] => Invalid taxonomy.
                )

        )

    [error_data] => Array
        (
        )

)

I've also tried using:

the_tags();

But that doesn't display anything. I've searched but I can't seem to find anything else that doesn't need the ID?

Any help would be appreciated!

Share Improve this question asked Nov 9, 2018 at 0:26 Leanne SeawrightLeanne Seawright 1032 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Taxonomies (and post types) need to be registered on init. You're registering them on admin_init:

add_action( 'admin_init', 'gccsi_create_client_tax' );

This means the taxonomy isn't registered on the front-end. Change the hook to init:

add_action( 'init', 'gccsi_create_client_tax' );

I'm very new to WordPress, but I've created a custom post type with two sets of tags. I've added the tags by using the following code:

/**
 * custom tags
 */
function gccsi_create_client_tax() {

    /* Teams */
    register_taxonomy( 
        'post_team', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Teams', CURRENT_THEME ), 
            'singular_name' => __( 'Team', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

    /* Locations */
    register_taxonomy( 
        'post_location', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Locations', CURRENT_THEME ), 
            'singular_name' => __( 'Location', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

}
add_action( 'admin_init', 'gccsi_create_client_tax' );

Which seems to work fine, I'm trying to now display those tags on the main page (which displays all items) so people can filter the listing page. I've tried the following:

$tagsTeam   = get_terms( 'post_team' ); ## I also tried get_terms( 'team' );
echo '<pre>';print_r($tags);echo '</pre>';

Which gives me this:

WP_Error Object
(
    [errors] => Array
        (
            [invalid_taxonomy] => Array
                (
                    [0] => Invalid taxonomy.
                )

        )

    [error_data] => Array
        (
        )

)

I've also tried using:

the_tags();

But that doesn't display anything. I've searched but I can't seem to find anything else that doesn't need the ID?

Any help would be appreciated!

I'm very new to WordPress, but I've created a custom post type with two sets of tags. I've added the tags by using the following code:

/**
 * custom tags
 */
function gccsi_create_client_tax() {

    /* Teams */
    register_taxonomy( 
        'post_team', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Teams', CURRENT_THEME ), 
            'singular_name' => __( 'Team', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

    /* Locations */
    register_taxonomy( 
        'post_location', ## tag name
        array( 'team', 'board' ), ## post type
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Locations', CURRENT_THEME ), 
            'singular_name' => __( 'Location', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )
    );

}
add_action( 'admin_init', 'gccsi_create_client_tax' );

Which seems to work fine, I'm trying to now display those tags on the main page (which displays all items) so people can filter the listing page. I've tried the following:

$tagsTeam   = get_terms( 'post_team' ); ## I also tried get_terms( 'team' );
echo '<pre>';print_r($tags);echo '</pre>';

Which gives me this:

WP_Error Object
(
    [errors] => Array
        (
            [invalid_taxonomy] => Array
                (
                    [0] => Invalid taxonomy.
                )

        )

    [error_data] => Array
        (
        )

)

I've also tried using:

the_tags();

But that doesn't display anything. I've searched but I can't seem to find anything else that doesn't need the ID?

Any help would be appreciated!

Share Improve this question asked Nov 9, 2018 at 0:26 Leanne SeawrightLeanne Seawright 1032 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Taxonomies (and post types) need to be registered on init. You're registering them on admin_init:

add_action( 'admin_init', 'gccsi_create_client_tax' );

This means the taxonomy isn't registered on the front-end. Change the hook to init:

add_action( 'init', 'gccsi_create_client_tax' );

本文标签: Display custom tags for custom post listing page