Answer to this question actually comes from @TomJNowell. Instead of using MySQL calls, use the native functions included with WordPress:
update_post_meta ( $post->ID , 'forum_id', $thread_id );
where the forum_id
is the key and the $thread_id
is the value. I tried add_post_meta
but that created duplicates.
To retrieve the meta data
$thread_id = get_post_custom_values( 'thread_id', $post->ID);
Now I’m looking at ways to add to the comment meta. Hopefully this helps someone else.
Related Posts:
- Should I use wpdb prepare?
- Is it mandatory to use $wpdb->prefix in custom tables
- $wpdb->insert_id
- Check for success of $wpdb->update() correctly
- WordPress and multithreading
- $wpdb->insert is changing a value
- Actions or filters fired when data is saved in a custom table
- Retrieving custom fields with $wpdb->get_results
- Really simple query giving error in SQL syntax
- Custom Plugin Database relations
- why creating tables using $wpdb is not being executed while installing plugins?
- How to use mysql IN statement with wpdb update method?
- Using $wpdb object in a widget
- Activation hook not creating table
- $wpdb -> Batch insert from XML File?
- How to Download and install plugin database remotely
- How to insert data to a database table when the field is not yet created?
- Where to store the name of a custom table?
- include wp-blog-header not working on MAMP
- creating custom function to log actions in plugin
- SQL query for custom taxonomy slugs
- Issue regarding $wpdb->prepare()
- Error on inserting a form value to database
- How to create database table, add data, update and delete using wpdb via plugins?
- Using WPDB to output raw XML fails because of wp-blog-header.php
- how to search users by ajax live search
- Adding custom end points, No error line
- Intermittent database errors when accessing WordPress database
- Storing data in wordpress database from ajax call from different website
- wpdb->prepare and mysql UPDATE – how is it done?
- $wpdb->prepare with LIKE and sprintf
- How to optimize multiple insert into wordpress database
- $wpdb->update() always need a second try
- Data inserted by wpdb insert is different than data pressnt in database.
- $wpdb->prepare is not working like mysql_real_escape_string
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- $wpdb in php 5.5
- Plugin to create Posts and Forums then choose category and parent forum
- $wpdb->update Issue
- How to relate the Category to user?
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Why doesn’t my Table get created?
- How to display specific data from a custom table to logged in users with a custom role
- $wpbd->insert_id is returning null
- How to store sensitive user data (passwords)
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- WordPress Query doesn’t return the correct value
- User avatar-ACF fields
- bindParam? WordPress 4.9.5 SQL LIKE statement %s and %LIKE%
- Update database record in plugin
- Dedicated server and WPDB Class : huge slow-down of the website
- How to implement pagination into a wpdb->result query?
- How to CRUD from wordpress database in wordpress theme?
- I can’t write in my DB using $wpdb->insert
- $wpdb how can i save my postmeta table before querying it
- WordPress plugin tables become corrupt
- Nothing happens on WordPress Update command
- Fixing plugin for wpdb::prepare
- multiple record insert creating many duplicate records
- Enhance Media Manager for Gallery
- Adding Custom Text Patterns in the WP 4.5 Visual Editor
- How to use PanelColorSettings in custom Gutenberg block?
- Is there a way for a plug-in to get it’s own version number?
- How do I print a notice only on certain admin pages?
- WordPress Settings API: saving multiple rows of similar data
- Modify how gallery.js builds the shortcode [gallery ...] in tinyMCE?
- DataBase connection problem with PHPUnit and WordPress
- Plugin settings not saving
- Registering and using actions which return results in a Plugin class
- How to replicate Media Library “Add New” on Plugin Settings Page
- WooCommerce Conditional Tag inside plugin
- Add code inside specific wordpress standard function
- Conditional hook based on the core function that is calling it
- Best way to save custom css for an block
- How to hook a custom user function to a wordpress core ajax action?
- How to change the hover content of a specific menu item on WordPress?
- Plugin callback page
- Is nonce in PHP form and Ajax both necessary?
- How to add WordPress Admin “Insert Link” UI (searches through existing posts for URL) and functionality into a custom plugin?
- Input in plugin widget does not allow spaces
- dbDelta SQL Query Not Working
- A question about add_action()
- How to display the categories on page using shortcode?
- How to Get Rid of Unwanted Backslashes in WordPress Form Input inside admin menu option
- wordpress automatic update does not run
- How to show multiple instances of the WP125 Widget?
- Posts form with AJAX request – Plugin development
- Want to know how to reveal a WordPress theme, considering the theme name is hidden?
- Where to add functions and code snippets in wordpress
- How to re-render inspector controls?
- Sanitize WordPress Array Input?
- Creating a virtual page without exit
- Plugin Development – Call to undefined function comment_exists()
- Allow user to change homepage
- wp_mail links are dead
- Is it safe to use PUT and DELETE requests
- Multi-part form and wp_redirect()
- Sharing changes to a post (preview changes) with another user
- Is there any other ways to replicating changes on live from staging without pushing from git
- upload image to wordpress media library failed for custom post type