Skip Navigation

[Resolved] Filtering by Custom Post Type in Views

This thread is resolved. Here is a description of the problem and solution.

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

Last updated by davidZ 4 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#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.