Skip Navigation

[Resolved] Creating checkbox filters to filter types

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.

Our next available supporter will start replying to tickets in about 5.37 hours from now. Thank you for your understanding.

This topic contains 3 replies, has 3 voices.

Last updated by Luo Yang 1 year, 8 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#1572863

Hi,

I have a couple of filters I need help with in an advanced search filter series...

1- I have selected two custom types (articles PI and Q&A PI) that can be filtered by this View... They work fine in the sense that when we do a search, it does search in both of them. BUT, I'd like to add two checkboxes (or maybe 3 radio buttons, one, the other or both) allowing them to choose to search only through one or the other (maybe the easiest would be to have a radio button set to both by default and the option of one or the other as the two other options)... How can I do that?

2- I have a custom text field and I'd like to display the results based on whether there is content or not in it. I.e. the field is called "Note from the master" and is a text field and I'd like a checkbox that when check will search for only articles where that field is not empty.

3- Finally, I have another custom type called numero PI (number PI, the number of the edition, being in fact the title). I have created a relationship between the numbers and articles of that number, and I have a date field in the number PI for the release date of that edition. I'd like to create a between filter based on the date edition, but I can't automatically. If I create a regular date between filter and use that field, it just doesn't work (empty result), because I guess it looks for the field inside both article PI and Q&A PI, which don't contain that field. If I use a relationship filter, I can only use the title (the number in this case) as a select...

Thank you for your help.

Nelson

#1573143

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As per our support policy, we entertain only one question per ticket. However, with this ticket, I will handle all the first questions you reported with this ticket and split the other questions as a new ticket.

1- I have selected two custom types (articles PI and Q&A PI) that can be filtered by this View... They work fine in the sense that when we do a search, it does search in both of them. BUT, I'd like to add two checkboxes (or maybe 3 radio buttons, one, the other or both) allowing them to choose to search only through one or the other (maybe the easiest would be to have a radio button set to both by default and the option of one or the other as the two other options)... How can I do that?
==>
Do you mean, you want to have radio buttons that users can use to display either both post types posts (articles PI and Q&A PI) or articles PI or Q&A PI. Is this correct? If yes:
- There is no such filter available to filter the posts by post types but there is a workaround. Please check the following related ticket link that will help you: https://toolset.com/forums/topic/post-type-filter/#post-486216
- With the above link, the post types configured as dropdown, you can change it to radio button.

#1573663

Hi,

Thank you for your answer.

I tried with radio buttons and, unless there is something else I need to change, it doesn't work... It's not too bad, though, I don't really mind using a drop-down instead...

The problem, as it is stated by other people possibly after it was marked as resolved, is that it only works the first time... If I change it and submit again, it then adds a second wpv-post-type to the url and keeps the previous results... How can we fix that?

#1575451

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hello,

You can register the URL parameter "wpv-post-type" to view's white list, for example, add below PHP codes in your theme file "functions.php":

add_filter('wpv_filter_register_url_parameters_for_posts', function($attributes, $view_settings){
    if($view_settings['view_id'] == 1234){
        $attributes[] = array(
            'query_type'=> 'posts',
            'filter_type'=> 'post_type',
            'value'=> 'custom_field_value',
            'attribute'=> 'wpv-post-type',
            'expected'=> 'string',
        );
    }
    return $attributes;
}, 99, 2);

Please replace 1234 with your post view's ID