Views is a WordPress plugin that lets you easily display content on your website's front-end in any way you choose.
Views User Guides include detailed documentation for creating lists of content, templates for content and archive page and also explain how to create parametric searches for any content type.
When you ask for help or report issues, make sure to tell us the versions of the Toolset plugins that you have installed and activated.
Viewing 15 topics - 1,531 through 1,545 (of 3,129 total)
Problem: I have a View of custom posts that displays a map with markers, using a distance filter and sorting results by distance. In some cases the distance center is set by a URL parameter, and in others, it is set by a shortcode attribute. I have implemented some custom code in a wpv_view_settings filter to toggle between the shortcode attribute and the URL parameter. In the cases where distance center is set by a shortcode attribute, I am using another custom shortcode to get the User's predicted zip code. That shortcodes an external service to get a predicted zip code based on the User's IP address. The custom zip code service seems to be working correctly, and the results of the View seem to be accurate.
However, in the cases where this zip code shortcode is used to set the View's distance Query Filter by shortcode attribute, the View consistently causes the page generation time to jump by 3 or more seconds. I would like to try to optimize the page load time as much as possible.
Solution: In this case, testing revealed that using the custom zip shortcode inside a wpv_view_settings filter callback was the source of the delay in page generation, for some reason not fully understood. Replacing that shortcode with a hard-coded zip code resulted in a page generation time just a fraction of a second higher than the page without the View present at all.
Optimization of the zip code shortcode is necessary to prevent the latency seen in page generation time.
Problem: If no items are found in a View of WooCommerce Orders, I would like to automatically refresh the View results after a set amount of time.
Solution: There is no automatic feature for refreshing View results, nor is there a true JavaScript API for Views, but you could achieve something similar by reloading the current page in a setTimeout function added to a script tag in the wpv-no-items-found block of the View, for example:
This will reload the current page after 5 seconds if no results are found in the View. That loop of refreshing every 5 seconds would continue until results exist.
Problem: I have a View that I would like to filter by post author. That View may be displayed in a BuddyPress profile. I have a PHP function provided by BB that will help determine the User ID based on the profile being displayed.
Solution: Use the Views Filter API wpv_filter_query to programmatically set a post author filter in this View using the function provided by BuddyPress / BuddyBoss.
// Override the post author filter of a View shown in the BP User page to display only that User's posts.
// https://toolset.com/forums/topic/filtering-views-query-by-author-for-a-profile-page/
add_filter( 'wpv_filter_query', 'tssupp_bp_force_author_filter',99,3 );
function tssupp_bp_force_author_filter( $query_args,$views_settings, $view_id) {
$views = array( 123, 456 );
if ( in_array( $view_id, $views ) ){
// post author equals bp_displayed_user_id() if function exists
$query_args['author'] = function_exists('bp_displayed_user_id') ? bp_displayed_user_id() : 0;
}
return $query_args;
}
You would replace 123, 456 with a comma-separated list of View IDs which you would like to filter by post author. This post author filter will only work if the function provided by BP/BB returns the correct User ID. If you try to place this View on a page where the BP/BB function does not return the correct value, the View will not be filtered appropriately.
Problem: I have a many-to-many relationship between two custom post types. In a two-column table View, I want to display the title of each post from post type A in the left column. In the right column, I want to display the average value of a custom field in all the related Type B posts.
Solution: There's nothing exactly like this built into the system, so it's probably best to create a custom shortcode that can be used to query related posts and calculate the average custom field value. See examples below.