dousilie9522 2018-07-28 06:24
浏览 60

get_terms WP_Error Object([errors] => Array([invalid_taxonomy] => Array([0] =>无效的分类法。))[error_data] => Array())[复制]

How to solve WP_Error Object for get_terms function ? I registered custom taxonomy tax_alone_event at the coustom-post-type.php file. and include at the functions.php file. Here is my code

function get__terms_list() {
  $terms = get_terms('tax_alone_event');
  return $terms ;

} //End get_terms_list()..

print_r(get__terms_list());

And I register custom post and custom taxonomy code at coustom-post-type.php file

function Alone_setup_post_type_project() {
    // event custom post and tax 
    $alone_event_args = array(
        'labels'             => array(
            'name'               => _x( 'Event', 'post type general name', 'alonefoundation' ),
             'add_new'            => _x( 'Add New', 'Event', 'alonefoundation' ),
             'add_new_item'       => __( 'Add New Event', 'alonefoundation' ),
             'new_item'           => __( 'New Event', 'alonefoundation' ),
             'edit_item'          => __( 'Edit Event', 'alonefoundation' ),
             'view_item'          => __( 'View Event', 'alonefoundation' ),
             'all_items'          => __( 'All Event', 'alonefoundation' ),
        ),
        'description'        => __( 'Description.', 'alonefoundation' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'event' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => true,
        'taxonomies'            => array('tax_alone_event'),
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'thumbnail')
    );
    register_post_type( 'alone-event', $alone_event_args );
    $alone_event_tax = array(
        'label' => __( 'Category' ),
        'rewrite' => array( 'slug' => 'event_tax' ),
        'hierarchical' => true,
    ) ;
    register_taxonomy( 'tax_alone_event', array('alone-event'), $alone_event_tax );
}

add_action( 'init', 'Alone_setup_post_type_project');
</div>
  • 写回答

4条回答 默认 最新

  • doute7910 2018-07-28 06:50
    关注

    You should pass taxonomies via the 'taxonomy' argument in the $args array from 4.5.0 - https://developer.wordpress.org/reference/functions/get_terms/.

    function get__terms_list() {
        $terms = get_terms( array( 'taxonomy' => 'tax_alone_event' ) );
        return $terms ;
    }
    
    print_r(get__terms_list());
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100