Change searched term

The pre_get_posts filter is the right place to go. You can check if you are on a search query, and alter it the way you want. Here’s an example: function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { // Check if we are on a search page if ($query->is_search) { // Get the search … Read more

Using $wpdb->update but confused on the WHERE in and SET

You need to look at the documentation for the function, which is available here. The function takes the following arguments: $table The table name. $data A PHP array where the keys are the columns and the values are the the values to be inserted into those columns. $where A PHP array where the key is … Read more

Strange string in console from wpdb query

That is a placeholder escape string generated by wpdb::placeholder_escape() which is used by wpdb::add_placeholder_escape() and which is called by wpdb::prepare(). So it is safe to keep those escape strings, but there is a wpdb method for removing them: wpdb::remove_placeholder_escape(): // In your case, you’d use $this->wpdb in place of $wpdb. $query = $wpdb->add_placeholder_escape( ‘LIKE %night%’ … Read more

Disable the MySQL query in the main query

Check if this solution work for your case: add_filter(‘posts_request’, ‘supress_main_query’, 10, 2); function supress_main_query( $request, $query ){ if( $query->is_main_query() && ! $query->is_admin ) return false; else return $request; } posts_request is the last filter called before running the query, and pass to you the $requestvariable with the generated SQL string and $query, with the WP_query … Read more

how to query multiple categories in wordpress?

Use like this query_posts( array( ‘category__in’ => array(5,1), ‘posts_per_page’ => 1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ) ); or $my_query = new WP_query(array(‘category__and’ => array(5,1))); while ($my_query->have_posts()) : $my_query->the_post();