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 7 Jahren. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 7 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Akhil vor 7 Jahren.

Assistiert von: 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

Sprachen: Englisch (English )

Zeitzone: 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

Sprachen: Englisch (English )

Zeitzone: 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.