Skip Navigation

[Gelöst] display all private posts types to admin and shop manager

This support ticket is created vor 4 Jahre, 3 Monate. 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.

This topic contains 1 Antwort, has 1 Stimme.

Last updated by davidZ-4 vor 4 Jahre, 3 Monate.

Author
Artikel
#1256485

Tell us what you are trying to do? Display all private posts created by all users to administrator and woo-commerce shop manager

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/forums/topic/how-to-use-wpv_filter_query/

Is there a similar example that we can see?
not sure

What is the link to your site?
hidden link

Initially i thought to use "wpv_filter_query" however used the following code:

add_action( 'pre_get_posts', 'see_private_posts' );

function see_private_posts( $query ) {
	// Make sure the query contains a post_type query_var,
	// otherwise it's definitely not a request for Task(s):
	if ( isset($query->query_vars['post_type']) ) {
		// Check if the request is for the Task post type…
		if ( $query->query_vars['post_type'] == 'client-portfolio' || ['post_type'] == 'personal-portfolio' ) {
			// … and the current user is admin or store manager:
			if ( current_user_can( 'shop_manager' ) || current_user_can( 'administrator') ) {
				// If so, Editors and Administrators see all private tasks…
				$query->set( 'post_status', 'private' );
			} elseif ( current_user_can( 'subscriber' ) ) {
				// … and Task Loggers see only their own tasks:
				$query->set( 'post_status', 'private' );
				$query->set( 'author', get_current_user_id() );
			}
		}
	}
}

not sure if i missed anything or if i should use another API call.
please advise,
thanks,
David

#1256513

My issue is resolved now. Thank you!