- Navigate to the ch4-book-reviews folder of the WordPress plugin directory of your development installation.
- Open the ch4-book-reviews.php file in a code editor.
- Find the call to the register_taxonomy function within the ch4_br_create_book_post_type function and add a new member to the configuration array named meta_box_cb with a value set to false highlighted in bold:
'show_tagcloud' => false,
'meta_box_cb' => false,
'hierarchical' => true
- Save the plugin and edit a Book Review to see that the Book Type taxonomy box is no longer displayed.
- Locate the ch4_br_display_review_details_meta_box function in the code and add the following code within the existing table rendering code to add a new row containing a drop-down selection box for the book type:
<tr>
<td>Book Type</td>
<td>
<?php
// Retrieve array of types assigned to post
$assigned_types = wp_get_post_terms( $book_review->ID,
'book_reviews_book_type' );
// Retrieve array of all book types in system
$book_types = get_terms( 'book_reviews_book_type',
array( 'orderby' => 'name',
'hide_empty' => 0) );
if ( $book_types ) {
echo '<select name="book_review_book_type"';
echo ' style="width: 400px">';
foreach ( $book_types as $book_type ) {
echo '<option value="' . $book_type->term_id;
echo '" ';
if ( !empty( $assigned_types ) ) {
selected( $assigned_types[0]->term_id,
$book_type->term_id );
}
echo '>' . esc_html( $book_type->name );
echo '</option>';
}
echo '</select>';
} ?>
</td>
</tr>
- Find the ch4_br_add_book_review_fields function and add the following code segment within the if statement, checking to see whether the post type is a Book Review, to save the selected book type in the site's database upon the submission of the post:
if ( isset( $_POST['book_review_book_type'] )
&& !empty( $_POST['book_review_book_type'] ) ) {
wp_set_post_terms( $book_review->ID,
intval( $_POST['book_review_book_type'] ),
'book_reviews_book_type' );
}
- Save and close the plugin file.
- Open a previously created Book Review to see the updated Book Review Details meta box containing a new drop-down list to specify Book Type:
