Hi there
Tell us what you are trying to do? I would like to add two views seamlessly together.
Is there any documentation that you are following? No
Is there a similar example that we can see? No
What is the link to your site? Here you can se our current setup:versteckter Link (in the tabs below in the tab "Mitglieder"). The two upper persons belong to one view, the person below to another view with the same settings.
I would like to have the third person on the first line as well. Is this possible with two separate views or can I combine the two views in a third view where I have a loop that adds another loop with a different view as soon as the first loop has ended?
If this is possible, that would acutally solve many challenges we currently face on this website.
Thanks a lot for your help!
Best,
Marcial
Hi, it's not easy to do this unless the number of results in each View never changes. It may be more practical to create a single View that includes all the results, filtered and sorted like you see here. Can you tell me more about why you currently need to use 2 Views? What are the Query Filters for each View? What order or sorting should be used? I might be able to make a recommendation, or offer some custom sorting help.
Hi Christian
We need two relationships in two post types, that's the issue.
Currently we use the two views because we have two different relationships that should be displayed:
Person --> Team Section
Manager --> Team Section
If we could use the "all relationship" filter and then say not the others, that would be amazing.
So the views do the following:
View 1: call all person who have the relationship team section
view 2: call all manager who have the relationship team section
Do you have another suggestion, how we could solve this?
Best, Marcial
I'm not quite clear about the relationships. Are these one-to-many relationships, or many-to-many relationships? If they are one-to-many, which post type is the parent and which post type is the child?
Can you share a screenshot of the Query Filters section in the View editor screen?
Hi Christian
They are many-to-many.
Just a quick question in between: I think we could easily fix the problem by switching the "manager" to the same post type as the other "persons" and chose a different layout for those that are "managers". Is it possible to change the URL of a "manager" to something different than what's the default for this post type?
The reason why I ask is because the problem is caused by the two post types. We need for the "managers" to check wheter they are "members" of this team-section (and display them if they are) AND check the same for the "person". The problem is that this are two different relationships (one for each CPT). But we can't use two relationships in one query filter. (--> is there a way to have only one relationship for both, like from many-to-one = many managers and many persons to one specific team-section?)
Therefore I was thinking about adding those two views together. Currently it separates them on a new line as you can see here: versteckter Link
Maybe you remember helping me in another ticket (https://toolset.com/forums/topic/order-posts-in-one-view-from-two-categories-and-alphabetically/) where we discussed something similar. The code there didn't worked (something else broke when enabling this, but I hadn't the time to investigate it yet) but maybe the same attempt would help us this time as well?
Thanks a lot for your help!
Best,
Marcial
I have an example using the Toolset and Views APIs that will allow you to show both post types in one View, while selecting only specific post relationships. First, remove the post relationship filter from this View. Then add code similar to this in functions.php:
add_filter( 'wpv_filter_query', 'query_specific_relationships',99,3 );
function query_specific_relationships( $query_args, $views_settings, $view_id) {
$view_ids = array( 12345 );
$related_ids = array( );
if (in_array($view_id, $view_ids)){
$rels = array('room-library', 'book-library'); // only query these relationships
$lib = get_post();
foreach( $rels as $rel ) {
$thisRel = toolset_get_related_posts(
$lib,
$rel,
'child',
9999999,
0,
array(),
'post_id',
'parent'
);
if ($thisRel) {
$related_ids[] = $thisRel[0];
}
}
}
$query_args['post__in'] = $related_ids;
return $query_args;
}
Replace 12345 with the numeric ID of this View. Replace 'room-library' and 'book-library' with the slugs of the two M2M relationships. This code assumes that the Team Section post type is set as the "child" in both M2M relationships. If that is not the case, I can show you some modifications you can make to fix that. I need to know which post type is the parent and which is the child in each M2M relationship. If you're not sure which is the parent and which is the child, edit the post relationship and check "I understand that changes to these settings may delete post associations in this Relationship", then click "Edit Settings". The parent and child will be defined here.
The code also assumes that 9999999 is the maximum number of related posts. The current API requires a positive integer here, so I selected a large number. There is a feature request to allow unlimited queries, but it's not implemented yet.
This code overrides any selections you make in a post ID filter in the View editor screen.