Custom table field to have same value as post title

Support MB Frontend Submission Custom table field to have same value as post titleResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #44540
    Nicholas CoxNicholas Cox
    Participant

    Hi

    I am using a custom table for 'products' and this links to a post type of 'products' all working ok but i want the post title to also be cloned to the custom table as a field e.g. product name. This is so for most queries i do inside my plugin i want to call the product custom table directly and dont need to call post data with it. So keeping my queries cleaner.

    So all im asking is it possible to pass in the id of 'post-title' as 'product_name? i could make 'product_name' as a hidden field. Or is it possible to pass more than one database column into post-title?

    'fields'  => [
    	[
    		'type'  => 'text',
    		'name'  => 'Title',
    		'id'    => 'post_title', 
    		'class' => 'dc-post-title',
    		'limit' => 50, //default character length
    		'required' => true,
    		//'save_field' => false,
    	],
    	[
    		'type'  => 'text',
    		'name'  => 'Name',
    		'id'    => 'product_name', <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    		'class' => 'dc-product-name',
    		'required' => false,
    	],
    ]
    #44558
    PeterPeter
    Moderator

    Hello,

    I think it is possible. You can create a new field group for the field product_name and save data to the custom table. Then use the action rwmb_after_save_post to hook a callback function to save post_title field value to the custom table.

    Following the documentation
    https://docs.metabox.io/actions/rwmb-after-save-post/
    https://docs.metabox.io/extensions/mb-custom-table/#update

    #44562
    Nicholas CoxNicholas Cox
    Participant

    Ok thanks i thought i would have to use 'rwmb_after_save_post' but was asking incase there was another way to do this without using 'rwmb_after_save_post'.

    #44601
    PeterPeter
    Moderator

    Hello,

    If you don't use the action hook rwmb_after_save_post, you can use the hook save_post. There isn't an option to save a field value with another field value without using code.

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