Custom Fields
Re-Envisioned
Support MB Custom Table Metabox Custom Table Model and CRUD Query

  • Creator
    Topic
  • #30257
    Nicholas Cox
    Participant

    Hi

    I was wondering, I am using Metabox Custom Table and tested out the new table 'model' system. All working fine by the way.

    public function createHousekeepingModel() {
            
        // Register a model
        add_action( 'init', 'dc_register_housekeeping_model' );
        function dc_register_housekeeping_model() {
    
            mb_register_model( 'housekeeping', [
                'table'  => "housekeeping",
                'labels' => [
                    'name'          => 'Housekeeping',
                    'singular_name' => 'Housekeeping',
                ],
                'menu_icon' => 'dashicons-money-alt',
                'show_in_menu' => false, //show hide in admin menu
            ] );
        }
    }

    The guide says that the model table is a CRUD system ("Complete CRUD for models so you can create/edit/delete them easily"). Do you have any metabox actions to insert, update and delete values into the database programmatically? without using the form fields? as for this one table I need to store system error logs. So no user interaction.

    or do I have to do it like in the below example?

    public function logEventAction($type, $date, $actiondate, $log) {    
        $this->wpdb->insert( 
            $this->table, 
            array( 
                'type' => $type,
                'date' => $date, 
                'action_date' => $actiondate, 
                'log' => $log, 
            ) 
        );
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #30269
    Long Nguyen
    Moderator

    Hi,

    I'm afraid that there is no action to CRUD data to the custom table without using custom fields. You need to use the methods of WPDB class.

    #30723
    Nicholas Cox
    Participant

    ok thanks, I will use the WPDB class then.

    #30726
    Long Nguyen
    Moderator

    Hi Nicholas,

    We've updated the documentation about the API to manipulate the custom table data. Please read more here https://docs.metabox.io/extensions/mb-custom-table/#api

    Let me know if it helped.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.