Skip Navigation

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

This support ticket is created hace 5 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Este tema contiene 1 respuesta, tiene 1 mensaje.

Última actualización por davidZ-4 hace 5 años, 6 meses.

Autor
Mensajes
#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?
enlace oculto

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!