Skip Navigation

[Resuelto] Auto detect CPT for widget.

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 12 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 7 respuestas, tiene 2 mensajes.

Última actualización por Akhil hace 6 años, 12 meses.

Asistido por: Minesh.

Autor
Mensajes
#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

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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.