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

Search for two strings in WP search

I am not 100% sure what you are trying to accomplish, but you can “search for both strings” simply by concatenating them: function checkForAa($query){ if($query->is_search){ $search_string = $query->get( ‘s’ ); if( stripos( $search_string , ‘aa’ ) !== false){ $new_string = str_ireplace( ‘aa’ , ‘xxx’ , $search_string ); }elseif( stripos( $search_string , ‘å’ ) !== false){ … Read more

Custom Query Content Filtering

I assume that your posts are having make and model as a Custom Fields and you want to retrieve all those posts which are matching both the passed value for make and model Custom Fields. If that is the case then your code seems to be correct. It might be possible that there is no … Read more

Search Results Page outputs HTML code

There is most likely a problem with escaping HTML in your code. You might be doing something like this: echo esc_html(“Search Results for: <span>search_word</span>”); Instead, use printf or only wrap your search word with esc_html(): printf(‘Search Results for: <span>%s</span>’, esc_html( $search_word ) ); Update The search results are rendered by search.php, most of the times … Read more

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