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

This wp_query will not return any posts and only seems to work with post_status inherit?

This part require(‘./wp-blog-header.php’); is all kinds of bad idea. And if your file is indeed in plugin folder then header isn’t even in that location. Custom loads of WordPress core are brittle and the technique is typically only justifiable for performance reasons. It would be better to structure your endpoint via creating actual rewrite endpoint, …

Read more

Conditional statement within WP SQL query

Here is one approach: $myrows = $wpdb->get_results( “SELECT first_name, surname, role, email, country, bio FROM members” ); foreach ( $myrows as $row ) { $first_name = $row->first_name; if ( ! empty( $row->bio ) ) { $first_name=”<a href=”#”>” . $first_name . ‘</a><div class=”bio” style=”display: none;”>’ . $row->bio . ‘</div>’; } echo “<tr><td>” . $first_name . “</td><td>” …

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