Skip Navigation

[Resolved] View filter by post type

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Shane 1 year, 11 months ago.

Assisted by: Shane.

Author
Posts
#2316357

Is there a way to create one view and include a filter by post type?

Essentially, I want to list the three newest posts in a post type separately for multiple post types.

I know I can do this by duplicating the view for each post type but that isn't very efficient especially if I want to change something about all of the views in the future.

I don't want all the post type lists in the same place so a nested view won't work.

#2316501

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

Thank you for getting in touch. Will this be a search view ?

If you want your view to display the different post types together you can make use of the order option to sort your view by the post type. This way your view will list out the same post types together.

Thanks,
Shane

#2316635

Thanks.

No this will be a simple list of the most recent three post titles for a CPT, so the view might be used to list three "properties" (CPT) on one page and three "cars" on another page.

Nick

#2316671

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

Ok thank you, in this case simply just sorting the view by the post type will allow you to be able to group your posts of similar post types together in 1 view.

Thanks,
Shane

#2318437

Thanks yes I see.

#2318439

Actually, that won't work. Maybe I am not being clear.

I would like one view which can on one page list the newest three of CPT1 and on another page can list the newest three of CPT2. Sorting by post type won't achieve that. I know I can create the same view over and over for each CPT but if possible I want to avoid that because I may want to change all of the views in some way later.

#2318613

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

You may be able to do this using the view filter queries and modifying the post type attribute.
Here is an example below.

add_filter( 'wpv_filter_query', 'show_post_list', 101, 1 );
 
function show_post_list( $query_args ) {
 global $post;
 if($post->ID == 123){   
 $query_args['post_type'] = 'my_post_type_slug';
 }
    return $query_args;
}

What this filter is doing is checking the page id to see if it equal to 123 and then modifying the view query's post type attribute to the slug of the post type that I want this page to display.

Please let me know if this filter helps.
Thanks,
Shane

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