Skip Navigation

[Resolved] custom search page not loading

This thread is resolved. Here is a description of the problem and solution.

Problem: The results on my custom search View never load. The page times out.

Solution: Add pagination so the View is not overloaded with results.

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Christian Cox 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#622258

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

#622271

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?

#622275

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

#622276

OR - is there a way to add a DEFAULT search criteria?

#622285

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.

#622299

Thanks!

For some reason, the addition to my functions.php did NOT work.

But adding the pagination DID work - so much appreciated!

Elise

#622300

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.