Products
GG网络技术分享 2025-03-18 16:12 2
<?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 360You 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
Demand feedback