Skip Navigation

[Resolved] Using a view shortcode for taxonomy, but also frontend filter for same taxonomy?

This support ticket is created 2 years, 3 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.

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 3 replies, has 2 voices.

Last updated by Alex Russell 2 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2451753

Tell us what you are trying to do?
I have a custom post type "Business" with a custom Taxonomy "Type-Of-Business" I have a page with multiple views, each accepting a view shortcode for a parent Type-Of-Business. I would like to be able to allow the user to filter down into the child types-of-business and use Ajax to update the results. For Example "Arts" would be the parent, then we want the user to be able to select from the child categories, "Art Galleries," "Music", "Comedy", "Theater", etc

[wpv-view name="communityguideviewfiltered" wpvtypeofbusiness="arts"] produces the desired result until I enable the taxonomy filter on the view, then it defaults to all businesses until the user selects a category from the dropdown.

As far as I can tell, we can use a view shortcode OR a frontend filter, but not both. Is this possible on Toolset?

What is the link to your site?

hidden link

#2452171

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As far as I can tell, we can use a view shortcode OR a frontend filter, but not both. Is this possible on Toolset?
==>
Yes, that is correct. Either you should go with filtering a view with shortcode attribute or use the frontend filter.

But I think I can share solution for this issue, let me see what I can offer. Can you please share admin access details and let me check if I can able to share any workaround.

*** 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.

#2453019

Minesh
Supporter

Languages: English (English )

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

I can see you are using the same view and adding shortcode attribute to filter it.

The best possible and dynamic solution I found is as given under.

I've added the following code to "Custom Code" section offered by Toolset with the code snippet "toolset-custom-code":
=> hidden link

add_filter( 'wpv_filter_query', 'func_filter_by_shortcode_attribute', 10, 3 );
function func_filter_by_shortcode_attribute($query, $setting, $views_ID){
   global $WP_Views;
  
    if($views_ID == 105198) {
      
       $passed_term =  $WP_Views->view_shortcode_attributes[0]['wpvtypeofbusiness'];  
 
         $query['tax_query'][] = array( 
             array(
            'taxonomy' => 'type-of-business',
            'field' => 'slug',
            'terms' =>$passed_term ,
            'operator' => 'IN'
        ));

      
    }
    return $query;
}


add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'func_filter_frontend_select_tax', 10, 3 );
 
function func_filter_frontend_select_tax( $args, $taxonomy, $view_id ) {
  global $WP_Views;
  
   if($view_id == 105198) {
  
  $passed_term =  $WP_Views->view_shortcode_attributes[0]['wpvtypeofbusiness'];  
  
    $found_term = get_term_by( 'slug', $passed_term, 'type-of-business' );
     
     $child_terms = get_terms('type-of-business', array('fields'=>'slugs','parent' => $found_term->term_id, 'hide_empty' => false ) );
    
    
    $args['slug'] = array($passed_term) + $child_terms;
     
   }
  
    return $args;
}

I can see now all view you added is automatically filtered:
- hidden link

Can you please confirm it works now. This is the best possible workaround I have to offer you.

#2453271

This is perfect, and does exactly what we need. My issue is resolved now. Thank you!