Skip Navigation

[Resolved] How to alter the wpv-control-post-relationship with wpv_filter_query

This support ticket is created 7 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 4 replies, has 2 voices.

Last updated by Luo Yang 7 years ago.

Assisted by: Luo Yang.

Author
Posts
#583238

Beda please ????

I have a view with a custom post-relationship filter that displays all post-type "BOOKINGS"

[wpv-control-post-relationship ancestors="organizer>event-plan>market>date" url_param="par"]
//form-fields
[/wpv-control-post-relationship]

The problem is that the filter shows ALL post-type "organizer, event-plan, market, date" available in the db.
I want to limit the filter fields to show only posts created by the logged in user.

I am unable to use the standard "post author filter" because post-type "bookings" can have any author.
The parent post-types I am filtering on, are all created by current user.

I am trying to build a filter but I dont know how to control the list of "ancestors":
The first ancestor is post-type "organizer".
My thought is to get all organizers created by current user and in that way limiting the first ancestor which in turn minimizes the following.

//Return only posts related to post-type:organizer where author=current user:
function prefix_check_org_author( $query_args, $view_id )
{
	if ($view_id == 19015) {
		global $current_user;		
		$organizer_args = array(
			'post_type' => 'organizer',
			'posts_per_page'=>-1,
			'author' => $current_user->ID,
		);
		$user_organizers = new WP_Query( $organizer_args );
		if ( $user_organizers->have_posts() ) {
			while ( $user_organizers->have_posts() ) {
				$user_organizers->the_post();
				$post_id_array[] = get_the_ID(); 
			}           
		}
		$user_organizers->reset_postdata();
		if ( !is_admin() ) {
			$query_args['post_relationship'] = in_array( how to limit ancestor organizer here?, $post_id_array );
		}
	}
	return $query_args;
}
add_filter( 'wpv_filter_query', 'prefix_check_org_author', 99, 2 );
#583771

Dear Tina,

There isn't such a built-in feature within Views shortcodes [wpv-control-post-relationship] and [wpv-control-item], see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-post-relationship

And
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-item

There isn't such an option to "limit the filter fields to show only posts created by the logged in user".

And shortcode [wpv-control-item] is using it's own sql query to get the parent posts from database, so your custom PHP codes won't be able to work, if you agree, we can take it as a feature request, our developers will evaluate it.

#585958

Yes I would very much like this. Please post a feature request.

#586519

As your request, I have forwarded it to our supporter Beda, he manages the feature request of Views plugin, but there isn't any ETA for implementing it.

#586521

As your request, I have forwarded it to our supporter Beda, he manages the feature request of Views plugin, but there isn't any ETA for implementing it.