Views plugin lets you build your own custom search for any content type. These searches can be based on post content, taxonomies and custom fields.
When you ask for help or report issues, make sure to tell us settings for your custom search.
Viewing 15 topics - 376 through 390 (of 751 total)
Problem: I would like to prevent search results from appearing until a custom search filter is added.
Solution: Use our PHP Views Filter API wpv_filter_query_post_process to drop a View's results until some meta_query is added. The following custom code can be used as a template:
/**
* No initial results until a filter has been applied
* Tests for one specific custom field search filter
* Reference: https://toolset.com/forums/topic/how-to-disable-the-search-in-view-using-blank/
*/
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
$target_views = array( 123, 456 );
$field_slug = 'field-slug';
// you should not edit below this line
if ( in_array( $view_id, $target_views ) ) {
// blank search indicates just blank space in the filter
$blank_search = isset($query_results->query['meta_query']) && sizeof($query_results->query['meta_query']) == 2 && $query_results->query['meta_query'][0]['key'] == 'wpcf-'.$field_slug && trim($query_results->query['meta_query'][0]['value']) == '';
// if there is no search term set, drop all results
if ( !isset( $query_results->query['meta_query'] ) || $blank_search ) {
$query_results->posts = array();
$query_results->post_count = 0;
$query_results->found_posts = 0;
}
}
return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );
Problem: I would like to know if it is better to include User data in User fields in the User profile, or to create a proxy post type as explained in the documentation for post relationships and custom search for Users?
Solution: There are pros and cons for each approach. If you plan to use custom search Views to search for Users based on filtering by these custom fields, or if you plan to use Repeatable Field Groups for some of these fields, or if you plan to use post relationships to connect multiple Users to the same post, a proxy post type is probably required as explained in the documentation link below.