Extending search query with additional $sentence value

Gladly I’ve written two plugins for that yesterday: Filter/Core That’s what a search query part looks like inside the posts_search filter: ‘ AND (((wp_XX_posts.post_title LIKE ‘%test%’) OR (wp_XX_posts.post_content LIKE ‘%test%’))) ‘ where wp_XX_ is just the $wpdb->prefix for my WPSE test site inside my local MU installation. Plugin #1 – drop searching post types that … Read more

Search by Post ID and display content of the post in search result

Put any of the filters in the functions.php Using pre get posts // Filter the search page add_filter(‘pre_get_posts’, ‘search_pre_get_posts’); function search_pre_get_posts($query) { // Verify that we are on the search page that that this came from the event search form if($query->query_vars[‘s’] != ” && is_search()) { // If “s” is a positive integer, assume post … Read more

How do I redirect /search/ to wordpress search template?

You can use template_redirect. Here a simple redirection function. add_action( ‘template_redirect’, ‘se219663_template_redirect’ ); function se219663_template_redirect() { global $wp_rewrite; if ( is_search() && ! empty ( $_GET[‘s’] ) ) { $s = sanitize_text_field( $_GET[‘s’] ); // or get_query_var( ‘s’ ) $location = “https://wordpress.stackexchange.com/”; $location .= trailingslashit( $wp_rewrite->search_base ); $location .= user_trailingslashit( urlencode( $s ) ); $location … Read more

How to insert a span inside a search form?

If we look at the source code of get_search_form(), notice that before the form gets rendered, the search_form_format filter hook gets fired. We can use that to add another filter attached to get_search_form where the callback is dependent upon the format. add_filter( ‘search_form_format’, ‘wpse_259716_search_form_format’, 99, 1 ); function wpse_259716_search_form_format( $format ) { if( in_array( $format, … Read more

How do I filter the search results order?

You can use the posts_orderby filter to alter the order of returned posts. This will run for every query (front and back), so make sure you ensure you want to alter the order by using is_admin, is_search etc. In the example below search results are ordered by post type in ascending order (e.g. page then … Read more

How to make WordPress search prioritise page titles?

You can replace the default WordPress search with something more useful. As you have pointed out, the build-in search is very limited. So you’re not the first one with this problem. I suggest the following two plugins: Search API (WordPress Plugin) WordPress Sphinx Search Plugin (WordPress Plugin) The last one allows to weight between parts … Read more

Unified search across separate WordPress installations

You should move your sites to the same server and same DB and then you will be able to run whatever queries you. Barring that, the only alternative I know to writing your own search engine is to use google’s site search API which gives you access to the raw data instead of the snippets … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)