Conflict with Categories / Tags and Lost Meta Boxes
-
Four years ago, I built a custom platform to add cycling records into a WordPress database. I used CPT UI to generate the code for the custom post type “record”. It all worked perfectly. I was away for a while, but now I’ve returned to find three big problems.
1) The “All Records” and “Add New” have disappeared from the Admin menu and been replaced by “Categories” and “Tags” (which didn’t use to be there). I can get “All Records” and “Add New” to appear if I disable the Child theme we are using. Plugins have no effect on the issue.
2) Once I can see “All Records” or “Add New”, when I edit an existing Record I cannot see any of the custom fields which were created with add_meta_box. The data is still in the WordPress database in the post meta table and I can query it with SQL. Ditto adding a new Record, doesn’t display any of the custom fields either.
3) The archive page of posts of type record is no longer loading, and some links to single posts of type record are also causing a 404.I don’t know what I should be checking to get the custom form to appear as it used to. Any pointers would be very helpful.
Code that was generated by CPT UI and had worked for years. In theme functions.php file:
function record_add_meta_boxes( $post ){
add_meta_box( ‘record_meta_box’, ‘Record Details’, ‘record_build_meta_box’, ‘record’, ‘normal’, ‘high’ );
}
add_action( ‘add_meta_boxes_record’, ‘record_add_meta_boxes’ );function record_build_meta_box( $post ){
wp_nonce_field( basename( __FILE__ ), ‘record_meta_box_nonce’ );
// Retrieve the custom field values to be managed through the meta box fields from the database
// Custom Fields:
// retrieve current values of Record post meta data
$current_rider_name = get_post_meta( $post->ID, ‘_rider_name’, true );
$current_legacy_rider_name = get_post_meta( $post->ID, ‘_legacy_rider_name’, true );
$current_age = get_post_meta( $post->ID, ‘_age’, true );
$current_age_group = get_post_meta( $post->ID, ‘_age_group’, true );
$current_rider_hometown = get_post_meta( $post->ID, ‘_rider_hometown’, true );
// Lots more….
?>
<div>
<!– all the HTML for displaying the form with custom fields –>
</div>
<?php
}function record_save_meta_box_data( $post_id ){
// verify taxonomies meta box nonce
if ( !isset( $_POST[‘record_meta_box_nonce’] ) || !wp_verify_nonce( $_POST[‘record_meta_box_nonce’], basename( __FILE__ ) ) ){
return;
}
// return if autosave
if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ){
return;
}
// Check the user’s permissions.
if ( ! current_user_can( ‘edit_post’, $post_id ) ){
return;
}
// store custom fields values – Rider Name
if ( isset( $_REQUEST[‘rider_name’] ) ) {
update_post_meta( $post_id, ‘_rider_name’, sanitize_text_field( $_POST[‘rider_name’] ) );
}
// Lots more fields saved}
add_action( ‘save_post_record’, ‘record_save_meta_box_data’ );Using CPT UI 1.7.3
Wordpress 5.3.2
PHP 7.1.33
The topic ‘Conflict with Categories / Tags and Lost Meta Boxes’ is closed to new replies.