从“REGISTERD_TASTIONY”挂接中获取分类名称

时间:2017-05-18 作者:Jaxy

我正在使用add\\u操作在创建分类法后运行函数。一切都正常,但我不知道如何获取分类名称。我想$args->name应该是一种方式,但它不起作用,没有返回任何内容。

function test( $taxonomy, $object_type, $args ) {
    $catname = $args->name;
}

add_action( \'registered_taxonomy\', \'test\',10, 3 );

1 个回复
SO网友:Milo

$args 是数组,而不是对象:

function test( $taxonomy, $object_type, $args ) {
    echo $args[\'name\'];
}
add_action( \'registered_taxonomy\', \'test\', 10, 3 );

EDIT

使用create_term 措施:

function my_create( $term_id, $tt_id, $taxonomy ){
    $term = get_term( $term_id, $taxonomy );
    echo $term->name;
}
add_action( \'create_term\', \'my_create\', 10, 3 );

结束

相关推荐

Custom taxonomy page template

我第一次在写我自己的wordpress主题。我用自定义分类法注册了一个新的帖子类型,但我无法按术语显示帖子。我复制了档案。php并将其重命名为taxonomy-[mycustomtaxonomy]。php并修改了几行。我保留了档案中的循环。php:<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php