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 badges1 Answer
Reset to default 1Taxonomies (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 badges1 Answer
Reset to default 1Taxonomies (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
版权声明:本文标题:Display custom tags for custom post listing page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749196037a2330993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论