I have created a custom search view with only one search parameter (on a custom field) - but when I put it on a page and try to load the page - it just spins and spins until I get a time-out error.
There are over 7,000 posts in the post type I am searching - but only two that meet the criteria that I put in the placeholder for the filter.
Here is my filter code:
[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
<label>[wpml-string context="wpv-views"]Activity Search[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-activity-search" url_param="wpv-wpcf-activity-search" placeholder="Music Director"]
</div>
<br><br>[wpv-filter-submit output="bootstrap"]
[/wpv-filter-controls]
[wpv-filter-end]
and here is the loop:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<br>
<br>
<table style="border:1px solid #000000">
<tr><td valign="top" style="border:1px solid #000000" colspan="5"><p>Total Results for this search: [wpv-found-count]</p></td></tr>
<wpv-loop>
<tr>
<td valign="top" style="border:1px solid #000000">[types field='activity-date' style='text' format='d/m/y'][/types]</td>
<td valign="top" style="border:1px solid #000000">[wpv-post-author format="meta" meta="first_name"]</td>
<td valign="top" style="border:1px solid #000000">[wpv-post-author format="meta" meta="last_name"]</td>
<td valign="top" style="border:1px solid #000000">[wpv-post-author format="meta" meta="user_email"]</td>
<td valign="top" style="border:1px solid #000000">[types field='activity-description'][/types]</td>
</tr></wpv-loop>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
It seems pretty simple, so I'm not sure what I'm doing wrong...
Thanks!
Elise
Hi, the text you add in the placeholder does not get applied to the filter when the page first loads, so most likely this View is trying to show all 7000 results. If you add pagination to this View, are the results shown in a reasonable amount of time without timing out?
I can try doing it without pagination - but how do I edit the current view to add pagination? I'm not seeing a spot.
Do I have to start over with a new view and choose pagination?
Elise
OR - is there a way to add a DEFAULT search criteria?
how do I edit the current view to add pagination? I'm not seeing a spot.
Scroll up to the top right corner of the editor screen in wp-admin, and click the "Screen Options" tab. You will be able to turn the Pagination panel on here. These panel options are defined when you start a View, but you can always change them later here.
OR - is there a way to add a DEFAULT search criteria?
Not exactly. You can create links to the page with the URL parameter and default value already in place, like hidden link. Or you can use custom code that shows no results until the user adds some search criteria manually. If that's something you would like to implement, add this code snippet to your child theme's functions.php file:
// drop all results for this View until the user adds something to the search filter
add_filter( 'wpv_filter_query_post_process', 'drop_empty_search_query_post_process', 10, 3 );
function drop_empty_search_query_post_process( $query, $view_settings, $view_id ) {
$ids = array( 123, 456 );
if (in_array($view_id, $ids)){
if (
// search filter check
( isset($_GET['wpv-wpcf-activity-search']) && $_GET['wpv-wpcf-activity-search'] != '' )
) {
} else {
$query->posts = array();
$query->found_posts = 0;
$query->post_count = 0;
}
}
return $query;
}
Replace 123, 456 with a comma-separated list of View IDs where you want to apply this custom filter.
Thanks!
For some reason, the addition to my functions.php did NOT work.
But adding the pagination DID work - so much appreciated!
Elise
I'll be glad to fix the code if you'd like to explore the other option. Please reopen the ticket if you'd like to discuss in more detail.