Search – Only search for post meta field

I’m not quite sure this is what you want (because it is so … easy), but all you need to do is add the following inputs to your search form: <input type=”hidden” id=”meta_key” name=”meta_key” value=”YOUR-META-KEY”> <input type=”hidden” id=”meta_value” name=”meta_value” value=”YOUR-META-VALUE”> Or, if you want to trigger the search by hand, do it like so: $search … Read more

Displaying number of search results for each post type

First, your callback to pre_get_posts is wrong. That is not the way that set works. If you had debugging enabled, you’d see Notices. It should be: function more_posts_per_search_page( $query ) { if ( !is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { $query->set(‘posts_per_page’,500); $query->set(‘post_type’,array( ‘author’, ‘book’)); } } } add_action( ‘pre_get_posts’,’more_posts_per_search_page’ ); Second, there … Read more

How to add one more query string with search query string

You should use ‘add_query_arg’ function, to do this. It adds a single key & value or an associative array. You can set a key value to false to remove it from the query. Omitting the old query or the uri (second or third parameter) uses the $_SERVER value. So in your case doing it like … Read more

How do i append UNION SQL Query with default search query

Append data to the native search: You can try for example: add_action( ‘pre_get_posts’, function( $q ) { if( $q->is_main_query() && $q->is_search() ) { $q->set( ‘nopaging’, true ); add_filter( ‘posts_request’, function( $request ) { $sql=”YOUR EXTRA SQL QUERY”; return “({$request}) UNION ({$sql}) ORDER BY post_status DESC”; }); } }); where we use the no paging version … Read more

Search.php display results differently based on post type

You can do something like this inside your loop if ( ‘machine’ == get_post_type() ){ //code for machine post types }elseif ( ‘post’ == get_post_type()){ //code for posts }elseif ( ‘page’ == get_post_type()){ // code for pages } else{ //code for anything else }

Make search result display 1 Company or 2 Companies

$found_posts holds the amount of posts found by a certain query. You can use this logic to display your links Example: if ( $allsearch->found_posts <= 1 ) { //Dispaly company } else { // Disply companies } Just a note on grammar, it should be 0 companies 1 company and x amount of companies after … Read more

Limit search to a specific folder in website

There is not “blog” folder in WordPress and the search is not done in folders, it is done in the database. I assume you mean limit the search to standard post types. You could add post_type argument to the search form to include only the standard post type: <form method=”get” class=”searchform” action=”<?php echo esc_url(home_url()); ?>/”> … Read more

Search buddypress groups with querystring in url

Not in the url, but you can pass other parameters in the groups loop. There is a search_terms parameter in bp_has_groups(). It also has an orderby parameter that accepts total_member_count as the property. Assuming the tag info is stored in group_meta, you can add a meta_query parameter to the bp_has_groups(). More info from the BuddyPress … Read more

Sort search results by Custom Field

I have managed to apply the proper sorting to the archive-data-base.php file Reading your question, I really do feel that you did not do your sorting correctly in archive-data-base.php as the same logic will be used for the search page as well. I do believe that you have used a custom query to correct the … Read more