How to properly sanitize strings without $wpdb->prepare?

I can’t use $wpdb->prepare, since I want to be able to add variables to my query string that look something like: $var = “AND pm.meta_value=”%$_POST[“val’]%'”; To get a literal % to pass through $wpdb->prepare just double it. You don’t need to be avoiding $wpdb->prepare. Proof of concept: var_dump($wpdb->prepare(‘SELECT * FROM {$wpdb->posts} WHERE post_title LIKE “%%%s%%”‘,’Hello’)); … Read more

prepare() not working

I agree with @bainternet. You don’t need $wpdb->prepare. There isn’t any user supplied content. The answer to the question is that to get a wildcard % to pass through prepare you need to double it in your code. LIKE ‘_transient_wb_tt_%%’ Try that or this if you want a good look at the generated query: var_dump($wpdb->prepare(” … Read more

SQL select of users by metadata

Double-check your SQL syntax. It sounds like you want to do a JOIN … But you’re not building the query correctly. It should be something more like: SELECT u.ID, u.user_login, u.user_nicename, u.user_email FROM $wpdb->users u INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID WHERE m.meta_key = ‘wp_capabilities’ AND m.meta_value LIKE ‘%supplier%’ ORDER BY u.user_registered You … Read more

register_post_status – show_in_admin_all_list & show_in_admin_status_list does not affect query

TL;DR: It’s not a bug (as we generally understand it), rather it’s a feature that was never fully implemented in WordPress. Status of register_post_status() register_post_status() function was never fully implemented in WordPress. If you check WordPress Codex entry for register_post_status() function, you’ll see it’s clearly mentioned in a notice: NOTICE: This function does NOT add … Read more

Sorting search results by taxonomy terms

Unfortunately, although WP_Query supports the ‘tax_query’ arg, it does not support ordering based on post terms. So you will need to modify the query SQL, as you are doing now. However, you are constructing the ORDER BY clause incorrectly, and that is why it is ordering by post_date. What you need to do is use … Read more

Use wpdb->prepare for `order by` column name

You can’t use prepare for column names, and you can’t really use it for the sort order either. prepare will always quote the string. You will need to swap in the values yourself. Rather than try to “sanitize” the data, I’d use a white-list approach. $orderby = array( ‘date’ => ‘post_date’, // etc ); $sortorder … Read more

SQL query to extract only the “current” wp_posts?

Rather than constructing query from scratch, it is easier to see what exactly is WordPress querying when API function is used: get_posts(array( ‘numberposts’ => -1, )); var_dump( $wpdb->last_query ); Gives following SQL: SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish”) ORDER BY wp_posts.post_date DESC

“This SqlTransaction has completed; it is no longer usable.”… configuration error?

I believe this error message is due to a “zombie transaction”. Look for possible areas where the transacton is being committed twice (or rolled back twice, or rolled back and committed, etc.). Does the .Net code commit the transaction after the SP has already committed it? Does the .Net code roll it back on encountering … Read more

ora-06553 pls-306 wrong number or types of arguments in call to ‘ogc_x’

you’ve used double quotes on “X”. this should be ‘X’. the X object is an function in the MDSYS schema, “ogc_x”, so when you say est.tipo_estatus = “X” instead of the correct est.tipo_estatus = ‘X’ it gets translated (as “” is as an identifier so “X” is the same as just typing X) to est.tipo_estatus = mdsys.ogc_x and of course fails.