Skip Navigation

[Resolved] Two questions about front-end filters

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 1 reply, has 1 voice.

Last updated by Saul Baizman 4 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2784015
screenshot 2024-11-15 at 17.18.25.png

Hi there,

I have a webpage displaying a directory of people (custom post types) whose roles are assigned by a taxonomy (team member type: staff, board, or trainer).

A view lists all of the people and has a custom search to let visitors filter between the staff, board members, and trainers. (A screenshot is attached for reference.) Here are my questions:

+ How can I order the taxonomy terms? Right now, they're in alphabetical order (board member, staff, trainer), but I need them to be in this order: staff, trainer, board.

+ When the page with the view initially loads, it displays all people regardless of role. Can I configure the view to display only the staff people as a default?

+ Can I change the language of the taxonomy terms in the filter? For example, to rename "Board Member" to "Board Members"? Or should I just rename the taxonomy terms in the WordPress dashboard?

Thanks for your assistance.

Saul

#2784066

Hi! I found an answer to my first question regarding re-ordering the taxonomy terms. I just used CSS grid-related properties.

#2784238

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL where you added your view as well as admin access details.

Once I review your views configurations I will be able to guide you in the right direction.

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

#2785217

Minesh
Supporter

Languages: English (English )

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

Well - I'm not sure what question you would like to address now.

I'm on this page:
- hidden link

Can you please tell me what issue you would like to address now as I do not see "Staff People" anywhere using which you wanted to filter the posts by default.

#2785280

Hi Minesh,

My apologies for the confusion. The page in question is called Our People:

hidden link

The related view is "View of Team Members" (ID 633).

The questions I'd like to answer are below:

+ When the page with the view initially loads, it displays all people regardless of "role." Can I configure the view to display only Staff as a default?

+ Can I change the language of the taxonomy terms in the filter? For example, to display "Trainers" as "Our Trainers"? Or should I just rename the taxonomy terms in the WordPress dashboard?

Thank you.

Saul

#2785978

Hey Minesh,

Any update on this ticket?

Thanks.

Saul

#2786058

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've added the following code to "Custom Code" section offered by Toolset:

add_filter('wpv_filter_query','func_prefilter_view_by_taxonomy_term',10,3);
 function func_prefilter_view_by_taxonomy_term($query_args, $settings, $view_id){
    if($view_id == 633 and ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX )){
       
      $query_args['tax_query'][] = array(
            'taxonomy' => 'team-member-type', // taxonomy name
            'field' => 'slug',
            'terms' => array( 'staff'), 
            'operator' => 'IN'
        );
     } 
    return $query_args;
}

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

Regarding changing the name, yes - you should just change the term name, please do not change term slug.

#2786148
screenshot 2024-11-28 at 09.47.13.png

Minesh,

The snippet of code did the trick! Thank you. The only thing remaining is to set the default radio button to be"Staff" (right now, none of the buttons are selected; see attached). Should I just use jQuery for that? Or is there a PHP solution?

Regarding changing the term names, I ended up using the Term Description field, where one can add anything one wants but it's otherwise hidden to users. 🙂

Thank you again!

Saul

#2786243

Minesh
Supporter

Languages: English (English )

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

Ok - in that case you do not require to use the snippet added to "Custom Code".

I've added the following line of the custom JS code to your view's "Search and Pagination" section JS editor:

jQuery(document).ready(function($){
  $('#team-member-type-staff').attr('checked', true).trigger('change');
});

Can you please confirm it works as expected now.

#2786257

Minesh,

Thanks for your response. This solution *almost* works. It works when the page initially loads, but if I select one of the other filters (such as Trainers) and then refresh the page (which now includes a query string), the "Staff" element is always highlighted. This will be confusing for sharing direct links to display just the Trainers or Board Members.

Saul

#2786514

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've adjusted the custom JS code added to your view's "Search and Pagination" section as given under:

jQuery(document).ready(function($){
  var params = new window.URLSearchParams(window.location.search);
  var myurl = new URL(window.location.href);

  // console.log(myurl.searchParams.has('wpv-team-member-type'));
  if(!myurl.searchParams.has('wpv-team-member-type')){
  	$('#team-member-type-staff').attr('checked', true).trigger('change');
  }
  
});
#2786871

Minesh,

This finally did the trick! Thanks so much for your persistence. I appreciate it!

Saul