Skip Navigation

[Resolved] display all private posts types to admin and shop manager

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

This topic contains 1 reply, has 1 voice.

Last updated by davidZ-4 4 years, 10 months ago.

Author
Posts
#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!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.