How do I update post based on meta_key in another table?

I couldn’t comment, because i dont have the rep Your code will not update because meta_key field is not in the wp_post table. First, you’ll want to query all posts where the meta_key wpcf-engine-days-to-go = 0 and then iterate through the post ID’s and make your changes to the wp_posts. Un-tested Example: $meta_value = 0; … Read more

How to fix this insert? Don’t work for me!

Make sure that the value portion of the data parameter’s column=>value pairs must be scalar. If you pass an array (or object) as a value to be inserted you will generate a warning similar to mysql_real_escape_string() expects parameter 1 to be string, array given on line 880 in file /var/www/html/wp-includes/wp-db.php”. Rather then above your code … Read more

MySQL Select within WP Page template

@Adrian, You don’t really need to assign anything to variables. You already have the information, you just need to loop through it and add the required HTML as you wish. If you actually want to use a table you can do something similar to: <table> <?php $myrows = $wpdb->get_results( “SELECT first_name, surname FROM members” ); … Read more

Run an update query in a function

As David pointed out, wpdb::query() does not allow multiple calls. So yes, it is because of having the “SET @newnum = 0;” before your actual query. This kind of query is simply not possible as the backend prevents that in order to protect against SQL injection attacks. Besides of that, the technique I described in … Read more

WPDP related functions look to work but they don’t

Formalizing comment answer here: Based on the code you provided the problem is possibly that you are using literal strings rather than interpolated values in your SQL. There’s a big difference between backticks ` and single-quotes ‘. try this: $retArray = $wpdb->get_row(“SELECT * FROM {$wpdb->prefix}wcpl_user_packages WHERE DATEDIFF(NOW(), package_timestamp) >= package_dduration AND id = {$package->id} AND … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)