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 - 2,836 through 2,850 (of 3,456 total)
Problem: I would like to allow my users to filter a View by the first letter of a custom field. For example, I want the user to be able to filter with "R" and show all results where the custom field value begins with "R".
Solution: There's no way to filter by the nth character in a field value. The best way to do this is to use two separate custom fields. The first custom field will contain the complete information, and the second custom field will contain only the first character of that information. You can choose to manually add this single character during the post creation workflow, or you can choose to write some PHP code that will handle it automatically upon saving a post.
Then, filter your View by the single-letter custom field to achieve the desired filter results.
Client's example PHP code to set this single character field automatically when a post is saved:
add_action('save_post', 'schreib_alf_v_sortname_upd', 100);
function schreib_alf_v_sortname_upd($id){
// only do this for reports post type
if (get_post_type($id) != 'reports')
return;
// get the lowercase first letter of the full field value
$a = lcfirst(substr(get_post_meta($id, 'wpcf-sortname', true), 0, 1));
// set the correct value of the single character field
update_post_meta($id, 'wpcf-alf', $a);
}
Problem: Post Type A and Post Type B are related in a many-to-many relationship by Post Type C (intermediary post type). On the Post Type A single post page, I would like to display a View of all related Post Type Bs, filtered by a taxonomy term.
Solution:
- Create a View of Post Type C, filtered by post relationship, where C is a child of the current post (Post A).
- It is not possible to filter Post Type C based on Post Type B taxonomy terms, so instead you can use conditional logic to show or hide each result based on Post Type B's taxonomy term (in this example, the term is "photographers", the taxonomy is "listing_cat", and Post Type B is "listing").
- Go to Toolset > Settings > Front end Content and find the "Functions inside conditional evaluations" section. Add has_term here.
- If empty category headers are appearing, you can apply the following JS:
Problem:
Ajax Filter is not working in Custom search view.
Solution:
The issue was in the theme.
Check it by deactivating all third-party plugins and switching back to the Default Theme (e.g. Twenty Sixteen theme) to see for any possible conflicts with any of the plugins or themes.