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 - 3,781 through 3,795 (of 3,852 total)
Problem:
The user is using WPML to translate the website and has a view with filters, results show up on the primary language and do not in the secondary language.
Solution:
Make sure that the posts are translated or duplicated to the secondary language.
Problem: I have a custom search View that includes 4 custom taxonomy filters. I would like to set one of the filters to a static value, so that all the results include one term from that custom taxonomy. Then I would like to use the relation "AND" to combine that with a group of 3 other custom taxonomy filters, which can be chosen on the front-end by the User, and combined using the "OR" relation. The combined effect should be like this graphic representation:
------------------------------------------------------
| Recipe Category (equal to "Shake") |
| |
| - AND - |
| |
| ____________________________________________ |
| | | |
| | Main Ingredient (set by URL parameter) | |
| | | |
| | - OR - | |
| | | |
| | Extra Ingredient (set by URL parameter) | |
| | | |
| | - OR - | |
| | | |
| | Fluid (set by URL parameter) | |
| -------------------------------------------- |
| |
-----------------------------------------------------
Solution: This type of combination of filters with nested AND/OR relations is not possible through the standard Views GUI, and requires a custom code solution. We offer the wpv_filter_query API that allows you to intercept the query and modify its tax_query details in real-time.
You can read more about complex or nested relations in taxonomy-based queries in the documentation linked below.
An example showing these APIs used together:
function tssupp_change_tax_query_and_or($view_args, $view_settings, $view_id)
{
$view_ids = array( 22575 ); // comma-separated list of View IDs where you want to apply this filter
$static_tax = 'recipe-category'; // the slug of the taxonomy that includes the static term "shake"
$static_term_id = 1084; // the term ID of "shake" in the static taxonomy "recipe-category"
/*
-- do not edit below this line --
*/
if ( in_array($view_id, $view_ids) ) {
// new tax query template
$new_tax_query = array(
array(
// code below will unshift selected front-end tax filters into this array
'relation' => 'OR',
),
array(
'taxonomy' => $static_tax,
'field' => 'id',
'terms' => array( $static_term_id ),
'operator' => 'IN',
'include_children' => 1,
),
'relation' => 'AND',
);
foreach ( $view_args['tax_query'] as $tax_query_term ) {
// loop over selected filters,
// verify is_array to skip 'relation' index,
// verify the slug of this tax is not
// same as the static taxonomy slug,
// unshift it into the new query's OR block
if( is_array($tax_query_term) && $tax_query_term['taxonomy'] != $static_tax ){
array_unshift( $new_tax_query[0], $tax_query_term );
}
}
// now overwrite the original tax_query with
// the new tax_query and you're done
$view_args['tax_query'] = $new_tax_query;
}
return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_change_tax_query_and_or', 99, 3);
Up at the top, modify the View if necessary to customize it for your site. You may add other View IDs to the $view_ids array in comma-separated format if you have more than one View with similar filters where you want to apply this custom snippet. I copied the taxonomy slugs and term IDs from the debug information, so I'm pretty sure those are correct.
Add the code in your child theme's functions.php file, or in Toolset > Settings > Custom Code, and test it on the front-end of the site. Let me know the results and we can go from there.
Problem:
The user uses Toolset Access to manage permissions on custom post types. He also has a view that displays several custom post types. This view displays some posts that are restricted to the current user.
Solution:
Views queries do not take into consideration Toolset Access permissions or the default WordPress permissions. For example, a default view will display only the published posts. But, if you choose to display the draft posts or the private posts, it will display them without taking into consideration WordPress default permissions.
CPTs post pages, instead, are bound to WordPress default permissions and Toolset Access permissions.
To be able to use the same view and display different CPTs for different kinds of users, the only way, is to use custom code. You will have to use the hook to modify the view's query post types based on the user type.
add_filter( 'wpv_filter_query', 'prefix_change_post_types' );
function prefix_change_post_types( $query_args, $view_settings, $view_id ) {
if ( $view_id == 123 ) { // change this ID with the ID of your view
$types = (array) $query_args['post_type'];
if ( !is_admin() ) {
// display only posts and pages for non admin users
$query_args['post_type'] = array( 'post', 'page' );
}
}
return $query_args;
}
Problem: I would like to create a grid of all the letters in the alphabet, and use those as filters for a custom search View. When you click a letter, the View should load posts filtered by a custom taxonomy term that corresponds the artist's name. The first letter of the artist name should be the same as the letter filter the User clicks.
Solution: WordPress does not allow searches by the first letter of a taxonomy term, so a workaround is required. In addition to applying the artist name as a taxonomy term, you must also apply a term from a separate custom taxonomy that represents the first letter of the artist's name. Your custom search View must filter by this taxonomy "letter" term. Create the grid of alphabetical letter filters using your own custom HTML, or use the built-in filter types to automate this filter list and use custom CSS to manipulate the styles for each filter.