Skip Navigation

[Resolved] Directory to display default search results

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Minesh 10 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2676942

Tell us what you are trying to do?

I am trying to build a directory page for an organization that allows viewers to search for any contact in the organization but by default shows a listing of the organization's leadership.

Is there any documentation that you are following?
https://toolset.com/course-lesson/creating-a-custom-search/#hide-the-search-results-until-the-first-search

Is there a similar example that we can see?

What is the link to your site?
hidden link

I have created the view and as per the documentation, added a conditional to the view output block. I want one view to show if there is a query value and another view to show if there is not.

So far no views are showing and my map is showing twice.

Please tell me what I am doing wrong.

cmkl

#2677026

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please tell me what things using what view you want to display when we are on the page first time and when you present the view with filters what view you want to display with filtered results?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2677142

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I understand - the page which you shared: hidden link

The above is a directory landing page.

Can you first just display all the content you wanted and get back to me. I see you have added a view block where one view block is empty, there is a map block as well as there is another view block that has two view loops (that is not correct).

Can you please first display all items you want on the above page and then get back to me with information about what section you want to hide and when?

#2677162

Hi Minesh.

I have reverted the directory page back to where it was before I tried getting complicated. hidden link this page shows all contacts as filtered, with pagination.

I have created a separate page just with the view that I want to appear on page load. It's here: hidden link

Obvs both are a work in progress, but the basics are in:

By default: show the search form and only certain contacts that are client's top leadership.
Search results: show paginated listing of contacts as chosen by the viewer.

#2677244

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

So when the page loads first time you want to show:
- By default: show the search form and only certain contacts that are client's top leadership.
==>
As I understand when page load first time - you want to display the map that is displayed at top of the page? If yes, what field you want to display with the map?

So map, search form that user can use to search and the default view what is available at the following page:
-hidden link

Is that correct?

#2677290

I think we're saying the same thing.

When the page loads the first time, show:
1.) The map with all the locals marked. When a visitor clicks on a marker they are offered a link to that local's contact page (this exists currently on hidden link)
2.) The search form allowing visitors to filter contact listings by geography, employer or by name (this exists currently on hidden link)
3.) The view that shows contact information for the organization's top leadership. (I have a working version of this view on this page hidden link)

When the visitor executes a search, show:
1.) The map with all the locals marked. When a visitor clicks on a marker they are offered a link to that local's contact page (this exists currently on hidden link)
2.) The search form allowing visitors to filter contact listings by geography, employer or by name (this exists currently on hidden link)
3.) The view that shows the results of the search (currently displayed beneath the search form on hidden link)

Thank you for whatever advice/help you can provide.

cmkl

#2677298

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

We do not need two views as we can manage this using the one view.

I've added the following view's hook to "Custom Code" section offered by Toolset:
- hidden link

add_filter( 'wpv_filter_query', 'func_default_tax_filter', 10, 3 );
function func_default_tax_filter( $query_args, $view_settings, $view_id ){
   
    if ($view_id==13416 
		and ( !isset($_GET['wpv_filter_submit']) and $_GET['wpv_filter_submit']!=='Search')){
        // your logic hear to alter the query arguments.
        // below a hardcoded example.  
        $query_args['tax_query'] = array(
            // Match all the conditions
            'relation' => 'AND',
            // Any of the following tags
            array(
                'taxonomy' => 'position',
                'field'    => 'slug',
                'terms' => array('national-president','national-vice-president','regional-vice-president'),
            )
        );
    }
   
    return $query_args;
}

What we are doing is we are checking if search is not performed yet then we will display the only posts who belongs to specific position taxonomy terms as you want.

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#2677310

That looks really promising, Minesh. Only thing is how do I order the results of the views hook? There's an order they have to be in. National President first, National Vice-President second, etc etc.

#2677518

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've added the following filter to "Custom Code" section that will help to order the posts as per your desired term order:
- hidden link

add_filter( 'wpv_filter_query_post_process', 'func_order_by_terms', 99, 3 );
function func_order_by_terms( $query, $view_settings, $view_id ) {
    
    if ($view_id == 13416 and ( !isset($_GET['wpv_filter_submit']) and $_GET['wpv_filter_submit']!=='Search') ) { 
   $res_posts = array();  
   $terms = array('national-president','national-vice-president','regional-vice-president');
    if ( !empty( $query->posts ) ) {
           
            $all_posts = $query->posts;
      foreach($terms as $x=>$y):
            foreach($all_posts as $k=>$v){
      			$term_slugs = wp_get_object_terms( $v->ID, 'position',array('fields'=>'slugs'));
              
                if(in_array($y,$term_slugs) ) {
                  $res_posts[] = $v;
                }
            }
       endforeach;
                
                 
              $query->posts = array_values($res_posts); 
             $query->found_posts = count($res_posts); 
              $query->post_count =  count($res_posts); 
                
    }        
  }
 
    return $query;
}

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

#2677617

Many thanks. And now on to the next