因此,我注册了一个自定义帖子类型以及该帖子类型的分类法。然后,我在该分类法中创建了两个项目,但当我单击其中任何一个时,发现它们是无效的分类法。
下面是我用来创建自定义帖子类型+分类法的代码。我有一个插件。
class GW_Guides_Post_Type {
public function __construct() {
$this->register_post_type();
$this->metaboxes();
$this->guides_taxonomy();
}
public function guides_taxonomy() {
register_taxonomy(
\'Guide Categories\',
\'gw_guides\',
array(
\'hierarchical\' => true,
\'label\' => \'Guide Categories\')
);
}
public function register_post_type() {
$args = array(
\'labels\' => array(
\'name\' => \'Guides\',
\'singular_name\' => \'Guide\',
\'add_new\' => \'Add New Guide\',
\'add_new_item\' => \'Add New Guide\',
\'edit_item\' => \'Edit Item\',
\'new_item\' => \'Add New Item\',
\'view_item\' => \'View News\',
\'search_items\' => \'Search Guides\',
\'not_found\' => \'No Guides Found\',
\'not_found_in_trash\' => \'No Guides Found In Trash\'
),
\'query_var\' => \'guides\',
\'rewrite\' => array(
\'slug\' => \'guides\',
),
\'public\' => true,
\'menu_position\' => 5,
\'menu_icon\' => admin_url() . \'images/media-button-other.gif\',
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\' ),
\'has_archive\' => true
);
register_post_type(\'gw_guides\', $args);
}
public function metaboxes() {
add_action(\'add_meta_boxes\',\'add_guides_meta\');
function add_guides_meta() {
// css id, title, cb funct, page, priority, cb funct arguments
add_meta_box(\'gw_guides_meta\', \'Featured\', \'guides_meta\', \'gw_guides\');
}
function guides_meta($post) {
$featured = get_post_meta($post->ID, \'featured\', true);
?>
<p>
<label for="featured">Featured:</label>
<?php
if ($featured == "True") {
$checked = \'checked\';
} else {
$checked = \'\';
}
?>
<input type="checkbox" name="featured" id="featured" value="True" <?php print($checked) ?> />
<?php echo $featured; ?>
</p>
<?php
}
add_action(\'save_post\', \'save_guides_meta\');
function save_guides_meta($id) {
update_post_meta(
$id,
\'featured\',
strip_tags($_POST[\'featured\'])
);
}
}
}
function add_gw_guides() {
new GW_Guides_Post_Type();
}
add_action(\'init\', \'add_gw_guides\');
?>