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,446 through 2,460 (of 2,484 total)
Problem:
How to add custom search to author page Solution:
To create author archive with custom search option you need to set the archive purpose to "Display the archive as custom search" and you will see the Filter editor available with your archive.
Problem: I have 4 categories: articles, video, audio, events.
I am searching for free text "basketball".
I want the results to show:
Results for "basketball" under "articles":
article-1, article-2, article 3
Results for "basketball" under "videos":
video-1, video-2, video-3
Results for "basketball" under "audio":
audio-1, audio-2, audio-3
Results for "basketball" under "events":
event-1, event-2, event-3
Solution:
There is not a good way to split up a single custom search View this way. Instead, you could use 4 separate custom search Views, each filtered by a single term. Then you can use conditional HTML to show and hide each View based on a URL parameter.
Add this custom shortcode to inspect URL parameters:
If the URL includes "wpv-post-typer%5B%5D=video", this shortcode will return 1. If not, the shortcode will return null. You can use the value of this shortcode to determine whether or not to display each View.
Problem: I would like to filter a View of Locations using start and end date custom fields in a child Event post, so that the View shows only Locations having Events that overlap with today's date. In other words, show only Events occurring today.
Solution: There's not an easy way to filter a View of post type A by custom fields in post type B, even if a parent/child relationship exists. I can offer some assistance with a View showing Events whose start and end dates intersect with a User-selected date. Then I can explain your options for getting Location information from those matching Events.
- First, create a View of Events. In the Filter editor panel, insert a filter on your start date custom field. If you cannot see the filter editor panel, scroll to the top of the View editor screen in wp-admin and click "Screen Options" in the top right corner. Check the box to display the Filter Editor panel. Configure the filter to show all Events with start dates greater than or equal to TODAY(), comparing values as numbers. The resulting shortcode will look something like this:
- In the Loop Output area, display the title, start, and end date of each matching Event for testing purposes.
- Next, add some custom code to your child theme's functions.php file:
add_filter( 'wpv_filter_query', 'default_today_inclusive', 10, 3 );
function default_today_inclusive ( $query, $view_settings, $view_id ) {
if( $view_id == 12345 ) {
// defaults
$selected_start = strtotime('0:00:00');
$selected_end = strtotime('23:59:59');
// if user selected a start date, update the default selected values accordingly, and unset existing start meta query
if ( isset($query['meta_query']) ) {
foreach($query['meta_query'] as $key => $meta) {
if(isset($meta['key']) && $meta['key'] == 'wpcf-start'){
// get timestamps that represents 12:00 am and 11:59:59 pm on the event start date
$selected_start = strtotime(date('m/d/Y', $meta['value']) . ' 0:00:00');
$selected_end = strtotime(date('m/d/Y', $meta['value']) . ' 23:59:59');
unset($query['meta_query'][$key]);
}
}
}
// find events with start date less than or equal to selected date
// and end date greater than or equal to selected date
$args = array(
'relation' => 'AND',
array(
'key' => 'wpcf-start',
'value' => $selected_end,
'compare' => '<=',
'type' => 'numeric'
),
array(
'key' => 'wpcf-end',
'value' => $selected_start,
'compare' => '>=',
'type' => 'numeric'
)
);
// add these arguments to your meta query
$query['meta_query'] = isset($query['meta_query']) ? $query['meta_query'] : [];
$query['meta_query'][] = $args;
}
return $query;
}
- Replace 12345 with the numeric ID of this View. If your field slugs are not "start" and "end", then the keys "wpcf-start" and "wpcf-end" should be updated as well. Add the "wpcf-" prefixes here.
- Show the parent Location information in the View.
The issue here is that the user wanted to display his posts in 2 columns with views.
Solution:
To do this when you are using the Loop Wizard in views. You can either select Table based grid or Bootstrap Grid and from here you can specify the number of columns that you want to be in the layout