Front-end submission to unrelated db table?
Support › MB Frontend Submission › Front-end submission to unrelated db table?Resolved
- This topic has 3 replies, 2 voices, and was last updated 4 years, 11 months ago by
Long Nguyen.
-
AuthorPosts
-
November 28, 2020 at 7:55 PM #23102
Martin Assheton
ParticipantHi, Is it possible to use front-end submission to update an unrelated db table please?
Many thanks, MNovember 28, 2020 at 10:10 PM #23103Long Nguyen
ModeratorHi Martin,
Yes, you can use action hooks
rwmb_frontend_before_save_postorrwmb_frontend_after_save_postto trigger a function to update some value to the database.It accepts 1 parameter
$object: the instance of the \MBFS\Post class, which handles the submission so you can access 4 properties:$post_type$post_id$fields$configSee more in the documentation https://docs.metabox.io/extensions/mb-frontend-submission/#post-actions.
November 28, 2020 at 11:23 PM #23104Martin Assheton
ParticipantHi Long,
Thanks for the prompt reply 🙂
If I wanted to use Meta Box and MB Frontend submission to quickly create front-end forms to collect data which is not post-related, here is one way I can utilise the ease of MB Frontend Submission to populate my custom table: On frontend submission of a field-group a new (CPT) post is created, add my submitted data to a custom table and then delete the newly created post using rwmb_frontend_after_save_post whilst keeping my Custom Table table data.
I cannot do this through MB custom tables as all db entry rows need to be associated with a post/user/taxonomy? Is that right?
Would this be an advisable execution or would you suggest another route?
The aim is to use the speed and flexibility coding with Meta Box and MB Frontend Submission, whilst adding data to custom tables which have no connection to posts, taxonomies or users.
Sorry for all the questions and if you have any advise in how to execute this via Meta-box I'd be very interested - Currently I have it all hard-coded and its a slow process to update/edit!
Ps. IF I Ajax call a post into a modal window (Bootstrap) using either admin-ajax or admin-post MB Frontend Submission will not execute - Is there are solution for this or is it out of scope for Meta Box please?
November 29, 2020 at 3:19 PM #23105Long Nguyen
ModeratorHi Martin,
Please follow this documentation https://docs.metabox.io/extensions/mb-custom-table/#query-posts-with-wp_query.
global $wpdb; $ids = $wpdb->get_col( "SELECT ID FROM your_table WHERE field1 = 'value1' OR field2 = 'value2'" );The custom table helps you track the data by post ID for each row and create the WordPress query to get full information base on post ID.
You can still keep the data in the custom table and query to the database to get the data even delete the post.
-
AuthorPosts
- You must be logged in to reply to this topic.