Wordpress taxanomy错误

时间:2017-06-10 13:40:08

标签: php 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' );

我创建wordpress插件,我不知道分类法,它给了我错误 如下.. 注意:未定义的变量:位置  第37行的C:\ XAMMP2 \ htdocs \ rateIt \ wp-content \ plugins \ job-listing.php  (这是第37行= register_taxonomy(&#39; location&#39;,$ args);) 注意:第360行的C:\ XAMMP2 \ htdocs \ rateIt \ wp-includes \ class-wp-taxonomy.php中的数组到字符串转换

1 个答案:

答案 0 :(得分:0)

您缺少object_type参数(taxonomy对象的对象类型的名称。对象类型可以是内置的Post Type或任何可能已注册的Custom Post Type,因此您需要使用它像:

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

以及$上的额外$slug符号。

请在这里查看此参考资料。

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