How do I use this for custom post types and/or custom taxonomies?
Use the rpc_post_types filter hook in your theme’s functions.php or a must-use plugin.
Usage examples:
function custom_rpc_post_types( $post_types ) {
// Add a key to the $post_types array for each post type and list the slugs of the taxonomies you wish to require
// Simplest usage
$post_types['book'] = array( 'genre' );
// Multiple taxonomies
$post_types['recipe'] = array( 'cookbook_category', 'geographic_origin', 'flavor_tags' );
// Set your own alert message for each taxonomy, or let the plugin generate the alert message
$post_types['inventory'] = array(
// Let the plugin generate a relevant alert message
'manufacturer',
// Or specify a custom alert message
'inventory_category' => array(
'message' => "Please choose a category for this fine inventory item."
)
);
// Always return $post_types after your modifications
return $post_types;
}
add_filter( 'rpc_post_types', 'custom_rpc_post_types' );
The default $post_types contains the following:
$post_types['post'] = array(
'category' => array(
'message' => 'Please select a category before publishing this post.'
)
);
This maintains the plugin’s original functionality. However, you can remove this functionality with unset($post_types['post']); or by redefining $post_types in your hook function.
You’ve added code to require a custom taxonomy but can’t get it to work in the Gutenberg editor?
One reason may be that your custom taxonomy does not have the show_in_rest argument enabled. Without it enabled the Gutenberg editor cannot access it.
Have a question that is not addressed here?
Visit this plugin’s WordPress support forum at https://wordpress.org/support/plugin/require-post-category