Tell us what you are trying to do?
Hello, I found a helpful thread that does what I need for 90% of the cases. But I would need to be able to set more than one post type occasionally .
Is there any documentation that you are following? - Is there a similar example that we can see?
https://toolset.com/forums/topic/modify-filter-by-post-type-shortcode-function-for-use-with-multiple-views/
i.e. [wpv-view name="countries-table" type="countries"] works fine
e.g. [wpv-view name="countries-table" type="communities,countries"] does not
THX
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Michael,
Thank you getting in touch.
To do this you will need to convert the comma separated string to an Array.
So it should be modified to
add_filter( 'wpv_filter_query', 'fbpts', 1000 , 3 );
function fbpts( $query_args, $view_settings ) {
$view_ids_array = array(1111, 2222, 3333);
if ( !is_admin() && isset($view_settings['view_id']) && in_array($view_settings['view_id'], $view_ids_array) ) {
global $WP_Views;
$attributes = $WP_Views->view_shortcode_attributes;
$att_array = explode(',', $attributes[0]['type']);
if (!empty($att_array)) {
$query_args['post_type'][0] = $att_array;
}
}
return $query_args;
}
Please try this and let me know if it helps.
Thanks,
Shane
Hello!
Sorry for delayed reply. Regrettably your code does not work :/
It seems to always returns "posts" in the view rather than the set post types.
E.g. with [wpv-view name="countries-table" type="communities,countries"] the view displays posts as type.
THX
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Michael,
Thank you for getting in touch.
Would you mind allowing me to have admin access to the site so that I can debug to see what is wrong here?
I've enabled the private fields for your next response. Also please let me know the page that you are testing this out on.
Thanks,
Shane
I removed your code from the functions file for now.
This post has the complete shortcode hidden link
Michael
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Michael,
Thank you for the credentials, I was able to fix the code. The below is the correct and final function.
add_filter( 'wpv_filter_query', 'fbpts', 99 , 3 );
function fbpts( $query_args, $view_settings, $view_id ) {
$view_ids_array = array(3762);
if ( !is_admin() && isset($view_settings['view_id']) && in_array($view_id, $view_ids_array) ) {
global $WP_Views;
$attributes = $WP_Views->view_shortcode_attributes;
$att_array = explode(',', $attributes[0]['type']);
if (!empty($att_array)) {
$query_args['post_type'] = $att_array;
}
}
return $query_args;
}
I've already added and activated this code in Toolset->Settings -> Custom Code.
Please let me know if you're seeing the correct results on your end now.
Thanks,
Shane
My issue is resolved now. Thank you!