Link to search page without search parameter

Create a file search.php inside your theme-folder. In this file you can design the search page and its functionality. Typically search page looks like this, <?php /** * The template for displaying search results pages * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result * * @package Torba_Market */ get_header(); ?> <div class=”container”> <section id=”primary” class=”content-area”> <main id=”main” class=”site-main” role=”main”> … Read more

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

Is there a more efficient admin search function/plugin?

Altering the WHERE clause There’s a filter named posts_search that allows to filter the SQL WHERE clause used for the query during search (when WP_Query::is_search() returns true and WP_Query->s is set): add_filter( ‘posts_search’, ‘wpse134392PostsSearchSQL’, 20, 2 ); function wpse134392PostsSearchSQL( $sql, $wp_query ) { // Alter SQL clause here return $where; } Custom ORDERBY To intercept … Read more

Custom slug in front of search URL

None of the above worked for me. Found another solution by overwriting the search rewrite rules using the search_rewrite_rules filter. 1 – Add this to the functions.php of your theme: add_filter( ‘search_rewrite_rules’, function($rules) { $new_rules = []; // New search slug here $new_search_slug = ‘zoeken’; foreach ($rules AS $key => $value){ $new_rules[str_replace(‘search’, $new_search_slug, $key)] = … 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

Custom search: by post data and post metadata?

The built-in WP search looks only a Posts’/Pages’ Title and Content, not thru other elements like Custom Fields and the content of Shortcodes. There’s a number of plugs that will search Custom Fields: http://wordpress.org/extend/plugins/wp-custom-fields-search/ http://wordpress.org/extend/plugins/search-everything/ http://wordpress.org/extend/plugins/relevanssi/ There also a filter apply_filters_ref_array() that “allows plugins to contextually add/remove/modify the search section of the database query.” FYI, … Read more