WP_User_Query not searching

WP_User_Query searches the $wpdb->users table. It will not join on your custom table. How would it know what to JOIN? The possible tables names and structures are practically infinite. I believe you might be able to use a filter on pre_user_query to insert your own values in the WHERE clause but there is no JOIN … Read more

WordPress custom search by post type

Yes, it is possible. You will have to use your custom SQL query though. Use posts_where filter to modify the query. function posts_where( $where ) { if( !is_admin() ) { $where = <YOUR CONDITION>; } return $where; } add_filter( ‘posts_where’ , ‘posts_where’ ); Your condition should look something like this: post_status=”publish” AND ((post_type=”post” AND post_title … Read more

I want empty search returns to home page in my wordpress

This will do exactly what you’re asking for: add_action(‘wp’, ‘redirect_empty_search’); function redirect_empty_search() { global $wp_query; if( isset( $_REQUEST[‘s’] ) && 0 === $wp_query->post_count ) { wp_redirect( home_url() ); exit; } } You’ll want to add some kind of message on the homepage when this happens, maybe by adding a query parameter to home_url() and displaying … Read more

Search using WP_Query

Add this line – <?php $search_query[‘post_type’] = ‘products’; ?> Just before the line – <?php $search = new WP_Query($search_query); ?>

Included posts on a page searchable

The problem is that by default WordPress only looks in the title and content field. As you build your pages from multiple pieces of external post types the default query doesn’t find those parts. Before we go any further I want you to know that this is going to be quite involved as you need … Read more

Search result count not matching actual result

If you want to exclude certain posts, wouldn’t the conditional be: if ($value != ” && get_post_meta($post->ID, ‘value’, true) != ‘value_to_exclude’) Anyhow, you’re excluding AFTER you run the query. So $total_results will always be ‘wrong’. The better approach is to write sql for WP_Query that does the excluding for you. But you didn’t include the … Read more