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 - 2,266 through 2,280 (of 2,903 total)
Problem:
Creating a List/Archive/Directory Page of Users with Filters
Solution:
You can not create custom search view for taxonomy or user views as its not supported natively. You can create custom search views for post type and post type archives.
The issue here is that the user wants to filter the current view by 2 post relationships from different post types.
Solution:
This can be resolved by using the code below.
//Return only posts from the current author when listing posts of type company:
function tssupp_filter_query( $query_args, $view_settings, $view_id ) {
if($view_id == 123){
$query_args['toolset_relationships'] = array(
array(
'role' => 'child',
'related_to' => 63,
'relationship' => 'leverancier-categorie-leverancier'
),
array(
'role' => 'child',
'related_to' => 51,
'relationship' => 'vestiging-leverancier'
)
);
}
return $query_args;
}
add_filter( 'wpv_filter_query', 'tssupp_filter_query', 99, 3 );
This can be added to the Toolset Custom code section in Toolset->Settings->Custom Code. Change the 123 to the ID of your view and adjust the relationship slug and related_to to the correct ID of the posts.
Problem: I have 3 custom post types - Artists, Books, and Works on Paper. I have two one-to-many (O2M) relationships: Artists-Books where Artist is parent and Book is child, and Artists-Works On Paper where Artist is parent and Work on Paper is child. I'm using the Favorites plugin to allow my site visitors to add favorite Books and favorite Works on Paper. In the list of favorite posts, I would like to display information about the related Artist.
Solution: The best way to handle this is to use the Favorites plugin's filters API to filter the favorites list HTML. You can use the Toolset Post Relationships API toolset_get_related_posts to get information from related posts in that filter callback:
/**
* Toolset Support
* Filter the Favorites list information to display related Artiste info
* Currently supports Livres and Oeuvres Sur Papiers post types for Favorites
* Extendable by adding a case statement for new post type / relationship slug
* https://toolset.com/forums/topic/find-related-custom-post-type/
*/
add_filter( 'favorites/list/listing/html', 'custom_favorites_listing_html', 10, 4 );
function custom_favorites_listing_html($html, $markup_template, $post_id, $list_options)
{
// relationship slugs per favorite post type
$post_type = get_post_type( $post_id );
switch($post_type) {
case "livre":
$rel_slug = "livre_artiste";
break;
case "oeuvre-sur-papier":
$rel_slug = "oeuvre-sur-papier-artiste";
break;
default:
return $html;
};
// Get related posts with Toolset post relationships API
$children_args = [
'query_by_role' => 'parent',
'role_to_return' => 'child'
];
$children = toolset_get_related_posts( $post_id, $rel_slug, $children_args);
// Build a string of related post titles, separated by a comma,
// and concatenate it into response HTML, then return it
$child_titles = [];
if( $children && count( $children ) > 0 ) {
foreach( $children as $child ){
$child_titles[]= get_the_title($child);
}
return $html . implode(',', $child_titles);
}
// in case no related posts are found, return the default HTML
return $html;
}