I’d use your friendly neighbourhood WP functions – look – here’s one!
In your case it would be something like:
...
$post_content = $this->add_image_dimensions( $post->post_content );
$update_post = wp_insert_post(
array(
'ID' => $post->ID,
'post_content' => $post_content,
)
);
// Don't forget error handling
if ( is_wp_error( $update_post ) ) {
$error_code = array_key_first( $update_post->errors );
$error_message = $update_post->errors[ $error_code ][0];
wp_die( "Post Update Error: Post ID: $post->ID - $error_message" );
}
...
That will correctly add slashes before adding to the DB so they can be stripped correctly on read.
If you do insist on running direct queries, prepare your damned write statements!
Related Posts:
- Is it fine to have foreign key as primary key?
- Detecting errors generated by $wpdb->get_results()
- Custom form that store input in database
- Restoring WordPress posts from database only
- Can a post ID be 0?
- Issue with wp_insert_post and post_content field error Could not update post in the database
- wp_posts – guid update
- Performance Gains of Relational DB Setup
- what is the wp_5_posts table in the database?
- Migrating data between local and development server
- WordPress Database Charset/Collate
- store simple data in get_option()
- What is the database table for pages?
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- What are conventions about the schema of the $table_prefix
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- BuddyPress: What’s the use of wp_bp_xprofile_data table and how does it get updated? [closed]
- storing database in version control
- Is deleting orphaned wp_options entries safe?
- How to build a movie database with wordpress?
- Sub-domain or 2nd, temporary different domain?
- Hook to be used when creating a database table
- Delete all post meta except featured image
- Where is custom template file chosen for a post stored in the DB?
- How do i get user data from a custom table in the wordpress database by user ID?
- Converting WordPress into Android or iPhone app
- Safe way to find last inserted id in a table?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Database slowdown after update to 3.4.1
- WooCommerce sku location in DB
- How to insert data into MySQL database from the form created in WordPress site
- WordPress DATABASE Update Manually?
- I don’t see site_url and home_url fields in wp_options table (phpMyAdmin)?
- Multiple postmeta with same name for one post in wp_postmeta table
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- Can I have multiple database users within WordPress?
- A field with dashes in the slug [closed]
- Modify Database in Multi-Site wp_usermeta table
- Structure of postmeta meta_value for woocommerce product download
- $wpdb doesn’t like to store arrays
- Connect to a remote database for wordpress in my own hosting server
- Handling large N data in WordPress
- Is MariaDB’s Aria storage engine suitable for WordPress?
- Difficulty importing my live site to local
- WordPress returns to an old version
- data (html) migration to posts
- Super slow queries from author archive pages killing my database
- localize elements in database
- How to fix database error duplicate entry
- WPDB SQL query with prepare() returning variable, not db value
- Get value form wordpress database
- Moving to another server database connection error [closed]
- Why this query is not showing any result on wordpresss home page?
- Best practice to limit results in get_row()?
- How to display content from external db with relevant urls
- Is there an easy way of exporting posts with their category already asigned and pictures from localhost?
- Connect to another WP install and grab post based on custom field
- Which table (and column) has the content of configured get_post_meta?
- Serialize data before inserting into the DB
- Pages from custom table
- Trouble running $wpdb->query() with last_insert_id
- content disappearing minutes after it’s published
- What is the most efficient way to reset a WordPress site?
- Add pdf to a website
- Optimizing function that automatically creates internal links based on post title string
- Can I customised default WP table
- Woocommerce – Check product stock availability from external database
- WordPress where clauses in db select
- How to display data from db in select list [closed]
- Will adding & modifying default WordPress table index break future WordPress update
- Database migration issues – Error #1046 No database selected
- echo site_url() returns a different value than what is in the database siteurl field
- Native timestamp on wp_options option
- _wp_attachment_metadata is not being added to database when PDF files uploaded
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to get the full stack trace for WordPress “table doesn’t exist” error in debug.log?
- How to access a table in a wordpress database using REST API?
- How do I loop/iterate through posts to edit all img tags?
- error establishing a database connection 3
- How to edit posts/pages without making the change live?
- Correct and secure way to access a custom SQL database in a custom PHP template file
- How to optimise this database query?
- How to retrieve user data based on role using SQL?
- Does WordPress Support Using Named Pipes on the Windows Operating System?
- Missing latest posts and options after DB migration via phpMyAdmin
- Split database on large site?
- Store the wordpress “featured image” under »wp_posts« Database table
- Custom metabox does not store data
- What WordPress file is saving new users to database
- wordpress database error
- How do i get value from wp_postmeta?
- Local host to server import problem
- featured image not showing up with mysql_connect
- Getting deleted users in database
- Options of accessing wordpress data from mobile app
- Getting data from a table using a query
- wp_usermeta key problem
- How to properly configure SSL connection to remote azure database for running queries within a WordPress environment
- Database Queries are crashing the server
- Uploading to WordPress Database