Skip Navigation

[Resolved] putting two or more relationship views side by side

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by martinE-4 4 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1531069

At this url: hidden link
I am showing two or more views. Currently if there are any posts, they appear one row under the other. I would like to have the 2nd view display on the same row as the first view (actually run together..).

1st view:
relates pages to posts
2nd view:
relates pages to resource cpt

I never know how many posts will be in these views but it would be nice if they ran together. I actually tried to combine them all into one view but after choosing the first relationship, I was never offered the chance in the block editor to choose a 2nd relationship. (even though I selected all the post types)

( PS in total, I actually have 4 relationships that I am trying to feature in this area but for simplicity in explanation I am presenting the question with just 2 relationship views)

#1531571

Hello,

I assume we are talking about the case:
Views 1(ID: 123) outputs multiple results:
Post A, Post B ...
Views 2(ID: 456) outputs multiple results:
Post C, Post D ...

You are going to merge above two view's result in one view, like this:
Post A, Post B, Post C, Post D ...

If it is, you might consider custom codes, for example:
1) Create another new view "View 3" (ID 123):
- Query posts of your custom post type
- Without any filter
- In view's loop, display the post information

2) Use filter hook wpv_filter_query to trigger a PHP function:

add_filter( 'wpv_filter_query', function( $query_args, $settings, $view_id ) {
    if($view_id == 789){
		$arr1 = get_view_query_results(123);
		$arr2 = get_view_query_results(456);
		$arr3 = array_merge($arr1, $arr2);
		$arr = array(0);
		foreach($arr3 as $post){
			$arr[] = $post->ID;
		}
		$query_args['post__in'] = $arr;
	}
    return $query_args;
}, 10, 3);

Please replace 123 with ID of view 1
replace 456 with ID of view 2
replace 789 with ID of view 3

3) Use "View 3" to display the result

More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#1533761

Works flawlessly. I actually merged 4 views no problem, from different custom post types. It was a great way to group them together in one bootstrap 4 column view. I love the way one set of posts seamlessly merges with the next! They become one view!

This was my code for the 4 views:

add_filter( 'wpv_filter_query', function( $query_args, $settings, $view_id ) {
    if($view_id == 3324){
        $arr1 = get_view_query_results(3236);
        $arr2 = get_view_query_results(3240);
	$arr3 = get_view_query_results(3238);
	$arr4 = get_view_query_results(2838);
        $arr5 = array_merge($arr1, $arr2, $arr3, $arr4);
        $arr = array(0);
        foreach($arr5 as $post){
            $arr[] = $post->ID;
        }
        $query_args['post__in'] = $arr;
    }
    return $query_args;
}, 10, 3);

My issue is resolved now. Thank you!