posts_where Fails with More than One Custom Field in Query

Think about your query. You are asking that $wpdb->postmeta.meta_key be both “foo” and “bar”. That will never happen. If you ran this in a context where you’d get to read MySQL debugging data (PhpMyAdmin’s SQL console will do this) you would probably see a warning about an “impossible where clause”. You need to JOIN on … Read more

$wpdb get_var issue

I’ll guess that $wpdb->specials isn’t giving you what you expect. custom tables have to referenced like $wpdb->prefix . ‘specials’

Update user_login, user_nicename, and display_name

You don’t need SQL, and shouldn’t use it when Core functions will do the job. Part of the reason why is the complexity of the tables (and the fact they might change). Query your users, loop through pulling metadata, and update Proof of concept: $u = new WP_User_Query( array( ‘role’ => ‘customer’ ) ); foreach … Read more

Cron While Editing Post

It seems to have solved by changing the two functions, by taking a different approach: /* CHECK IF CURRENT USER IS NOT IN POST.PHP AND IN POST-NEW.PHP AND DOWNGRADE PUBLISH POSTS IN PENDING AFTER X DAYS */ if(is_admin() ) {global $pagenow; if( ‘post.php’ != $pagenow || ‘post-new.php’ != $pagenow) { add_action( ‘init’, ‘downgrade_publish_posts’ ); function … Read more

Backticks (`) Instead of Single Quotes (‘) in an SQL Statement?

Backticks and regular quotes (both single and double) have distinct meanings in SQL. Quotes indicate a literal string, whereas backticks are quoted identifiers. This isn’t specific to WordPress, but rather a general way in SQL of quoting columns or tables. For example, imagine you’re running a query comparing two columns: SELECT * FROM wp_posts WHERE … Read more

WordPress SQL LIKE request doesn’t work for fields with special symbols

What I miss here? How to search through any elements in this field? Your SQL statements, or the LIKE ‘%a%’ and LIKE ‘%full%’, are good. But the wpdb::prepare()‘s documentation says, “Literal percentage signs (%) in the query string must be written as %%“, hence you should actually use LIKE ‘%%a%%’ and LIKE ‘%%full%%’. But then … Read more

How To Write An Inner Join With WP Query

Ok so the way I was able to just show English properties on the user admin page was with this posts_request hook: add_filter(‘posts_request’, function($sql, $query) { $is_user_edit_page = ( isset($_SERVER[‘HTTP_REFERER’]) && strpos($_SERVER[‘HTTP_REFERER’], ‘user-edit’) !== false ); $is_property_sql = (strpos($sql, ‘property’) !== false); if ($is_user_edit_page && $is_property_sql) { $sql = str_replace(“‘sp'”, “‘en'”, $sql); } return $sql; … Read more