Skip Navigation

[Gelöst] Auto detect CPT for widget.

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
How to auto-detect the post type for widget view

Solution:
You can use "wpv_filter_query" hook to modify the view's query arguments on fly.

You can find proposed solution with the following reply.
https://toolset.com/forums/topic/auto-detect-cpt-for-widget/#post-593258

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created vor 6 Jahre, 5 Monate. 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
- 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 7 Antworten, has 2 Stimmen.

Last updated by Akhil vor 6 Jahre, 5 Monate.

Assisted by: Minesh.

Author
Artikel
#593009

HI.

i have created a views to use at widget area.
i have 6 cpt.
i am wondering if there is anyway i could just create 1 views and set it as auto detect the cpt and display its latest post.

i really dont want to create 6 views and load it one by one to layout.

#593010
#593127

i using this shortcode, but its doing the fetching but just displaying the conditional items

[wpv-conditional if="( '[wpv-post-type]' eq ' post-type' )"]
Post type
[/wpv-conditional]

#593258

Minesh
Supporter

Languages: Englisch (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I think you need to use view's filter wpv_filter_query .

For example - try to add following code to your current theme's functions.php file:

add_filter( 'wpv_filter_query', 'filter_post_type_func', 99, 3 );
function filter_post_type_func( $query_args, $view_settings, $view_id ) {
 
global $post;

   $display_view_ids =     array(99999);
    
if ( in_array($view_id,$display_view_ids ) ) {
               $query_args['post_type'] =  $post->post_type;
}
    return $query_args;
}

Where:
- Replace 99999 with your original view id.

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#593263

exactly what i am looking for. thank you .

#593270

sorry. i need to ask

what if i have 10 view id to enter ?

thanks again.

#593273

Minesh
Supporter

Languages: Englisch (English )

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

You can comma separate the view IDs as given under.

$display_view_ids =     array(99999,123,456,878,8585);
#593278

ok. thanks.

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