How to insert Collate into WordPress search query?

You should add the following code to the functions.php of your theme (and it is better to make all modifications in child theme): add_filter( ‘posts_search’ , ‘posts_search’ ); function posts_search( $search ) { $search = str_replace( ‘LIKE’, ‘COLLATE utf8_bin LIKE’, $search ); return $search; } It works. You can check it on my test site: … Read more

Query Column of Specific ID from Database Table

You have 2 two problems here: – You can’t use $wpdb-> with custom tables because [postmeta, posts, …] are variables in the class $wpdb. – WHERE ‘id’= 2 is not correct WHERE id = 2 So it should work: global $wpdb; $table_name = “_customtable”; $retrieve_data = $wpdb->get_results( “SELECT * FROM $table_name WHERE id = 2” … Read more

Related post based on content

I’m too low level to comment but maybe this WP guide can help you. I didn’t want to copy and paste their answer in case it was against WPSE.

SQL query to set posts in bulk based on the post content

Look into MySQL Wildcards. The correct MySQL Query for your search should be WHERE tb_posts.post_content LIKE “%example.com%” You should also be sure that you only target published posts (in contrast to nav_menu_items, revisions etc). Expand your WHERE with this: AND tb_posts.post_type IN (‘post’,’page’,*All Posttypes you use additionally*) AND tb_posts.post_status=”publish” So your complete Query should look … Read more

PHP -> SQL Query with Summing

Looking at this, I see that “Paid”, a string, isn’t in quotes. That would cause an error. You can add $wpdb->show_errors() and $wpdb->print_error() methods to reveal that, and any other mysql issues. Also when querying the database, you should use the $wpdb->prepare() method to escape and prepare your variables for query (yes $user->ID probably can’t … Read more