Skip Navigation

[Résolu] display all private posts types to admin and shop manager

This support ticket is created Il y a 5 années et 6 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Ce sujet contient 1 réponse, a 1 voix.

Dernière mise à jour par davidZ-4 Il y a 5 années et 6 mois.

Auteur
Publications
#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?
lien caché

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!