$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Display custom tags for custom post listing page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Display custom tags for custom post listing page

matteradmin10PV0评论

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' );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far