I'm on WordPress 4.7.4 and on my custom post types, I cannot assign tags as a regular user.
I have used CPTUI for creating everything, have mapped and created custom capabilities, have assigned roles to the custom caps, and have verified the user's roles are correct using get_userdata()
, but I can't seem to get this working.
On the CPT, the taxonomies variable has post_tag
set and I can see the tags meta box, I just can't do anything with it. I have tried to separate the term capabilities using the function below and the user has the assign_post_tags
role, but it doesn't seem to do anything. Any help would be greatly appreciated.
Register CPT:
function cptui_register_my_cpts_listing() {
/**
* Post Type: Listings.
*/
$labels = array(
"name" => __( 'Listings', 'text-domain' ),
"singular_name" => __( 'Listing', 'text-domain' ),
);
$args = array(
"label" => __( 'Listings', 'text-domain' ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => "archive-listing",
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "listing",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "listing", "with_front" => true ),
"query_var" => "listing",
"supports" => array( "title", "editor", "thumbnail" ),
"taxonomies" => array( "post_tag", "location" ),
);
register_post_type( "listing", $args );
}
add_action( 'init', 'cptui_register_my_cpts_listing' );
Changing caps
function set_builtin_tax_caps() {
$tax = get_taxonomy('post_tag');
$tax->cap->manage_terms = 'manage_post_tags';
$tax->cap->edit_terms = 'edit_post_tags';
$tax->cap->delete_terms = 'delete_post_tags';
$tax->cap->assign_terms = 'assign_post_tags';
$tax = get_taxonomy('category');
$tax->cap->manage_terms = 'manage_categories';
$tax->cap->edit_terms = 'edit_categories';
$tax->cap->delete_terms = 'delete_categories';
$tax->cap->assign_terms = 'assign_categories';
}
add_action('init', 'set_builtin_tax_caps');