doubengman2072 2017-06-10 13:40
浏览 97
已采纳

Wordpress分类法错误

<?php
/*
Plugin Name: job list
Plugin URI: http://example.com/
Description: A complete and practical example of use of the Settings API. This plugin creates a new plugin administration page.
Author: WROX
Author URI: http://wrox.com
*/
function dwwp_register_taxonomy() {
    $singular = 'Location';
    $plural = 'Locations';
    $slug = str_replace( ' ', '_', strtolower( $singular ) );
    $labels = array(
        'name'                       => $plural,
        'singular_name'              => $singular,
        'search_items'               => 'Search ' . $plural,
        'popular_items'              => 'Popular ' . $plural,
        'all_items'                  => 'All ' . $plural,
        'parent_item'                => null,
        'parent_item_colon'          => null,
        'edit_item'                  => 'Edit ' . $singular,
        'update_item'                => 'Update ' . $singular,
        'add_new_item'               => 'Add New ' . $singular,
        'new_item_name'              => 'New ' . $singular . ' Name',
        'separate_items_with_commas' => 'Separate ' . $plural . ' with commas',
        'add_or_remove_items'        => 'Add or remove ' . $plural,
        'choose_from_most_used'      => 'Choose from the most used ' . $plural,
        'not_found'                  => 'No ' . $plural . ' found.',
        'menu_name'                  => $plural,
    );
    $args = array(
            'hierarchical'          => true,
            'labels'                => $labels,
            'show_ui'               => true,
            'show_admin_column'     => true,
            'query_var'             => true,
            'rewrite'               => array( 'slug' => $$slug ),
        );
    register_taxonomy( 'location', $args );
}
add_action( 'init', 'dwwp_register_taxonomy' );

I creating wordpress plugin and i dont know taxonomy well it is giving me error as follows.. Notice: Undefined variable: location in C:\XAMMP2\htdocsateIt\wp-content\plugins\job-listing.php on line 37 (this is line 37= register_taxonomy( 'location', $args );) Notice: Array to string conversion in C:\XAMMP2\htdocsateIt\wp-includes\class-wp-taxonomy.php on line 360

  • 写回答

1条回答 默认 最新

  • dp926460 2017-06-10 14:27
    关注

    You are missing the object_type argument (Name of the object type for the taxonomy object. Object-types can be built-in Post Type or any Custom Post Type that may be registered) so you need to use it like:

    register_taxonomy( 'location', array('post type / custom post type') $args );
    

    as well as an extra $ symbol on the $slug.

    please have a look of this reference here.

    https://codex.wordpress.org/Function_Reference/register_taxonomy

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题