Skip Navigation

[Résolu] Filtering by Custom Post Type in Views

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

Add post type filter into post view, I would like to display the options as radio button.

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/filtering-by-custom-post-type-in-views/#post-1443847

Relevant Documentation:

This support ticket is created Il y a 4 années et 3 mois. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 2 réponses, has 2 voix.

Last updated by davidZ Il y a 4 années et 3 mois.

Assisted by: Luo Yang.

Auteur
Publications
#1442971
Screen Shot 2020-01-06 at 9.47.57 AM.png

I'm trying to accomplish something like this:
https://toolset.com/forums/topic/filtersearch-by-custom-post-type/

But instead of a Select field, I would like to display the options in a menu, similar to the attached.

I thought I could use Radio instead of Select, but that doesn't seem to work with this function. Might there be a way to output the options as an unordered list that can be styled like this?

Thanks!

#1443847

Hello,

You can try these:
1) Modify the codes in filter editor, as below:

[wpv-filter-controls][wpml-string context="wpv-views"]Post Type:[/wpml-string] [wpv-control url_param="wpv-post-type" type="radio" values=",page,post" display_values="All,Page,Post"]

2) Modify the PHP codes as below:

add_filter( 'wpv_filter_query', 'post_type_filter_func', 10, 3 );
   
function post_type_filter_func( $query_args, $settings, $view_id ) {
    if ( $view_id == 9999 && isset($_GET['wpv-post-type']) && !empty($_GET['wpv-post-type']) ) {
        $query_args['post_type'] = $_GET['wpv-post-type'];
    }
    return $query_args;
}

Replace 9999 with your View's ID, and test again

#1443915

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.