I'm using DevinVinson/WordPress-Plugin-Boilerplate as the base of the plugin, I already created a custom post type as book
and a taxonomy linked to it as rack
.
What I need is to limit the number of books to 10 per rack; if the number exceeds, it should save the post as a draft and show an error.. lost right now .. need help..
Here's what I have so far!
private function define_admin_hooks() {
$this->loader->add_action( 'save_post', $plugin_admin, 'save_post' );
$this->loader->add_action( 'admin_notices', $plugin_admin, 'admin_notices' );
}
I've another admin class in which the above mentioned functions are defined
public function save_post( $post_id ) {
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (isset($_POST['post_type']) && $_POST['post_type'] == 'book') {
// If the book is assigned to taxonomy "rack" having more than 10 books, the admin_notices function is to be called
return;
}
}
public function admin_notices() {
if ( ! isset( $_GET['YOUR_QUERY_VAR'] ) ) {
return;
}
?>
<div class="error">
<p><?php _e( 'Max Book limit reached for the selected rack!', 'odin-lms' ); ?></p>
</div>
<?php
}