admin管理员组文章数量:1430083
I'm trying to create a new category in the taxonomy.php called 'USSERS'. I have followed few examples online and got till this part.
function insert_term( $name,$tax,$parent='' ,$slug='') {
$term_id = term_exists( $name, $tax);
if ( !$term_id)
$term_id = wp_insert_term( $name, $tax, array('parent'=>$parent,'slug'=>$ludg) );
return $term_id;
}
insert_term('USSERS','category');
After doing the above code, i went to check the wordpress dashboard to see if I actually created the category but It doesn't show. So now i'm confused and lost because I have no idea how to proceed with the above code and make it show on the dashboard.
FUNCTIONS.PHP
<?php
if ( function_exists('register_sidebar') )
register_sidebar();
add_filter( 'auto_update_plugin', '__return_false' );
add_filter( 'auto_update_theme', '__return_false' );
?>
function yourtheme_init() {
insert_term('USSERS','category');
}
add_action('init', 'yourtheme_init');
function insert_term( $name,$tax,$parent='' ,$slug='') {
$term_id = term_exists( $name, $tax);
if ( !$term_id) {
$term_id = wp_insert_term( $name, $tax, array('parent'=>$parent,'slug'=>$slug) );
}
return $term_id;
}
I'm trying to create a new category in the taxonomy.php called 'USSERS'. I have followed few examples online and got till this part.
function insert_term( $name,$tax,$parent='' ,$slug='') {
$term_id = term_exists( $name, $tax);
if ( !$term_id)
$term_id = wp_insert_term( $name, $tax, array('parent'=>$parent,'slug'=>$ludg) );
return $term_id;
}
insert_term('USSERS','category');
After doing the above code, i went to check the wordpress dashboard to see if I actually created the category but It doesn't show. So now i'm confused and lost because I have no idea how to proceed with the above code and make it show on the dashboard.
FUNCTIONS.PHP
<?php
if ( function_exists('register_sidebar') )
register_sidebar();
add_filter( 'auto_update_plugin', '__return_false' );
add_filter( 'auto_update_theme', '__return_false' );
?>
function yourtheme_init() {
insert_term('USSERS','category');
}
add_action('init', 'yourtheme_init');
function insert_term( $name,$tax,$parent='' ,$slug='') {
$term_id = term_exists( $name, $tax);
if ( !$term_id) {
$term_id = wp_insert_term( $name, $tax, array('parent'=>$parent,'slug'=>$slug) );
}
return $term_id;
}
Share
Improve this question
edited Apr 25, 2019 at 16:15
user166752
asked Apr 25, 2019 at 15:14
user166752user166752
34 bronze badges
2 Answers
Reset to default 0Where are you calling this code? You need to add it to one of the init hooks.
If I add that to either a plugin or theme init, then it adds just fine for me, with the $slug
typo corrected as Mike pointed out.
echo '<p>Debug: Loaded functions.php</p>';
function yourtheme_init() {
echo '<p>Debug: called yourtheme_init</p>';
insert_term('USSERS','category');
}
add_action('init', 'yourtheme_init');
function insert_term($name,$tax,$parent='', $slug='') {
echo '<p>Debug: called insert_term</p>';
$term_id = term_exists($name, $tax);
if (!$term_id) {
echo '<p>Debug: adding new term</p>';
$term_id = wp_insert_term( $name, $tax, array('parent'=>$parent,'slug'=>$slug) );
echo '<p>Debug: new term added with ID ' . $term_id . '</p>';
} else {
echo '<p>Debug: term already exists with ID ' . $term_id . '</p>';
}
die('<p>Debug: end</p>');
return $term_id;
}
You misspelled $slug
as $ludg
.
本文标签: phpcategory not display in word press grammatically
版权声明:本文标题:php - category not display in word press grammatically 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745551969a2662984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论