wpdb prepare syntax

Just look at the generated string: INSERT INTO ‘wp_table’ (id, datea, one, two) VALUES (1, ‘2013-12-24’, 3, ‘NULL’) ON DUPLICATE KEY UPDATE one = VALUES(one), two = VALUES(two); The problem is the quotes around the table name. (Your hand-written query has no quotes around the table name, and works.) prepare is intended for dynamic user … Read more

Extending the database

I’m not sure why you’re getting a 1. Your code says that you should not. However, it seems that what you’re doing is unnecessary and generally ill-advised. Modifying existing tables is usually not needed. The wp_comments table contains a comment_parent and user_id column. So if I reply to a comment, it’s immediate parent ID is … Read more

query to create woocommerce products from images

I’d agree that doing this in SQL would be a lot more to learn than PHP. With WordPress functions you can run a query on all the images ( WP_Query ) and then loop through the results and use the info from the images to create a new post using [wp_insert_post()][2]. Finally you can update … Read more

Updating User Meta with SQL Query

How can I write a bulk MySQL command to add in the value wp_capabilites=”a:1:{s:10:”subscriber”;b:1;}” into each user_id except 1, 2 and 3 ie. the newly imported users? You don’t. That is a serialized array which is a PHP construct. MySQL has no idea what to do with it. To the database, it is just an … Read more

wpdb Custom Meta Data with 2 conditions

I found my error in the above query. There still may be a better way to do this, thank you kaiser, and I will update once I’ve done more study. What I forgot to do was GROUP_CONCAT another meta_value so i could pull out different bits. It still seems longer than it needs to be, … Read more

#1115 – Unknown character set: ‘utf8mb4’

WordPress does not support MySQL 4 : To run WordPress your host just needs a couple of things: MySQL version 5.0 or greater (recommended: MySQL 5.5 or greater) https://wordpress.org/about/requirements/ While the utf8mb4 encoding is recent change and you might work around it, overall you still need compatible MySQL version.

Fulltext search in posts sorted by relevancy

You may want to check the Sphinx search engine http://sphinxsearch.com/ It took me about one day to set it up and learn how to use, but it does really good job with sorting by relevancy and grammar stemming. Also it is faster than fulltext search for big data sets thanks to indexing.

SQL query to update post_date (one post = one single date & time)

I would not do this with SQL. A relatively simple PHP loop should work. function bulk_schedule_posts_wpse_105834() { $args = ( array( ‘cat’ => 1, ‘posts_per_page’ => -1, ‘post_status’ => ‘draft’, ‘post_type’ => ‘post’, ) ); $posts = new WP_Query($args); if (!$posts->have_posts()) return false; $date=”2013-08-01″; $times = array( ’10:00′, ’14:00′, ’17:00′, ’20:30′ ); while ($posts->have_posts()) { … Read more