Data for Model does not show (except record ID#) plus Warning for line 689
Support › MB Custom Table › Data for Model does not show (except record ID#) plus Warning for line 689
-
AuthorPosts
-
April 30, 2026 at 4:22 AM #49939
KG
ParticipantHello,
Since the code snippets (below) are a little long, first want to say I appreciate the help!
Here's the problem I'm having:
I created a custom model and custom database table, but when I click on the model ("States Model") the editor shows all 63 IDs for the 63 records in the table, but none of the data fields are visible. When I open the database table through LocalWP (AdminNeo), all the data is present for all the records.
When I click to edit one of the records (or try to add a new record), I receive this Warning:
Warning: Attempt to read property "post_title" on null in /home/ls/Local Sites/bptest-backup-26-02-17/app/public/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php on line 689
This is the code from the .php file. Line 689 is the echo statement:
/**
* Output extra data on post forms.
*
* @param WP_Post $post Current post object.
*/
public function edit_form_top( $post ) {
echo '<input type="hidden" id="original_post_title" name="original_post_title" value="' . esc_attr( $post->post_title ) . '" />';
}In case some background information is helpful. The model I'm trying to create is for geolocation/mapping and will only be used for looking up values. Since it's census bureau / tiger web data, it will be checked for accuracy once or twice a year, but that's about it. In other words, I don't need a post for the data, but I would like to see it in the back end for testing purposes, etc.
Cutting and pasting, messed the spacing up, but here's the code I used to create the model / custom table / metabox:
// Step 1: Register a model.
add_action( 'init', function() {
mb_register_model( 'statesmodel', [
'table' => 'cc_geo_states',
'labels' => [
'name' => 'States Model',
'singular_name' => 'State',
'add_new_item' => 'Add State',
'edit_item' => 'Edit State',
'search_items' => 'Search States',
'not_found' => 'State Not Found',
'all_items' => 'States and Territories',
'item_updated' => 'State Updated',
'item_added' => 'State Added',
'item_deleted' => "State Deleted"
],
'menu_icon' => 'dashicons-location-alt'
] );
} );add_action( 'init', function () {
MetaBox\CustomTable\API::create(
'cc_geo_states', // Custom table name.
[ // List of columns with data types.
'st_name_id' => 'INT'
'stype' => 'VARCHAR(1)',
'state_base_name' => 'VARCHAR(45)',
'state_abbr' => 'VARCHAR(2)',
'mtfcc' => 'VARCHAR(5)',
'oid' => 'BIGINT',
'geoid' => 'VARCHAR(12)',
'state' => 'VARCHAR(2)',
'statens' => 'VARCHAR(8)',
'region' => 'VARCHAR(1)',
'division' => 'VARCHAR(1)',
'state_full_name' => 'VARCHAR(45)',
'lsadc' => 'VARCHAR(2)',
'funcstat' => 'VARCHAR(1)',
'arealand' => 'DOUBLE',
'areawater' => 'DOUBLE',
'centlat' => 'DECIMAL (10,8)',
'centlon' => 'DECIMAL (11,8)',
'intptlat' => 'DECIMAL (10,8)',
'intptlon' => 'DECIMAL (11,8)',
],
[ 'state_abbr' ], // List of columns that will be indexed.
);
} );add_filter( 'rwmb_meta_boxes', function ( $metaboxes ) {
$meta_boxes[] = [
'title' => 'States Details',
'models' => ['statesmodel'],
'storage_type' => 'custom_table',
'table' => 'cc_geo_states',
'fields' => [
[
'id' => 'state_name_id',
'name' => 'state_name_id',
'type' => 'number',
],
[
'id' => 'stype',
'name' => 'S Type',
'type' => 'text',
],'id' => 'state_base_name',
'name' => 'state_base_name',
'type' => 'text',
'admin_columns' => true,
],
[
'id' => 'state_abbr',
'name' => 'state_abbr',
'type' => 'text',
'admin_columns' => true,
],
[
'id' => 'mtfcc',
'name' => 'mtfcc',
'type' => 'text',
],
[
'id' => 'oid',
'name' => 'oid',
'type' => 'number'
],
[
'id' => 'geoid',
'name' => 'geoid',
'type' => 'text',
],
[
'id' => 'state',
'name' => 'state',
'type' => 'text',
],
[
'id' => 'statens',
'name' => 'statens',
'type' => 'text',
],
[
'id' => 'region',
'name' => 'region',
'type' => 'text',
],
[
'id' => 'division',
'name' => 'division',
'type' => 'text',
],
[
'id' => 'state_full_name',
'name' => 'state_full_name',
'type' => 'text',
],
[
'id' => 'lsadc',
'name' => 'lsadc',
'type' => 'text',
],
[
'id' => 'funcstat',
'name' => 'funcstat',
'type' => 'text',
],
[
'id' => 'arealand',
'name' => 'arealand',
'type' => 'number',
],
[
'id' => 'areawater',
'name' => 'areawater',
'type' => 'number',
],
[
'id' => 'centlat',
'name' => 'centlat',
'type' => 'number',
'admin_columns' => true,
],
[
'id' => 'centlon',
'name' => 'centlon',
'type' => 'number',
'admin_columns' => true,
],
[
'id' => 'intptlat',
'name' => 'intptlat',
'type' => 'number',
'admin_columns' => true,
],
[
'id' => 'intptlon',
'name' => 'intptlon',
'type' => 'number',
'admin_columns' => true,],
]
];return $meta_boxes;
Thanks, Kellie
-
AuthorPosts
- You must be logged in to reply to this topic.