Require users to choose a post category before updating or publishing a post.
Tired of uncategorized posts? Use this simple plugin to require users to choose a post category before updating or publishing a post. By default this only applies to normal posts. If you wish to require a category/taxonomy for a custom post type see the FAQ for filter hook usage examples.
If you have created your own language pack, or have an update of an existing one, you can send the PO and MO files to me so that I can bundle it into the plugin. Download the latest POT file.
Nope, just install and activate, that’s it!
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.
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.
Visit this plugin’s WordPress support forum at https://wordpress.org/support/plugin/require-post-category
rest_base
value of boolean false was not being properly handled.wp_enqueue_script
and wp_localize_script