Skip Navigation

[Resolved] Trying to show a differente archive for different user roles.

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.

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/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 1 year, 4 months ago.

Assisted by: Waqar.


I'm trying to show two archives, one for admins/shop managers another for the rest.
The issue is that I'm using a combination of blocks and legacy.

This is as far as I got and it semi-worked:

	<!-- wpv-loop-start -->
	<div class="mainLoopML">
	<wpv-loop wrap="3" pad="true">
      	[wpv-conditional if=" NOT ( ( '[wpv-current-user info="role"]' eq 'administrator' ) OR ( '[wpv-current-user info="role"]' eq 'shop_manager' ) ) "]
		[wpv-item index=1]
		<div class="child">
            [wpv-post-body view_template="76687"]
		[wpv-item index=other]
		<div class="child">	
			[wpv-post-body view_template="76687"]
		[wpv-item index=3]
		<div class="child">
			[wpv-post-body view_template="76687"]
        [wpv-conditional if="  ( ( '[wpv-current-user info="role"]' eq 'administrator' ) OR ( '[wpv-current-user info="role"]' eq 'shop_manager' ) ) "]
          		[wpv-post-body view_template="70421"]
	[wpv-pager-archive-nav-links output="bootstrap" first_last_links="true" previous_next_links="true" step="100" reach="4"]
	<!-- wpv-loop-end -->
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>

Using only blocks I know I can do it since I'm already doing it for other things, but with this mix, basically the conditional display is the issue and I'm not sure how to solve.

I could just do the conditional display in the blocks (sure) but the issue there is that I want the layout to be different, for admins/shop managers I want the current layout which is a list-type product, that's 1 product per line, whereas for non-admins I want 3 products per line in a card-type style.

Thank you.



Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)


Thank you for contacting us and I'd be happy to assist.

From the "semi-worked", do you mean that conditional statements are not working as expected or they're working, but you'd prefer an alternative where you don't have to use this combination of blocks and legacy?

You're also welcome to share temporary admin login details so that I can see how these different layouts are set up. I'll be in a better position to suggest some recommendations, accordingly.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.




Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing these details.

I'll review your website's setup, perform some tests on my website, and then share the findings, accordingly.

Thank you for your patience.



Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting.

During testing on my website, I was able to make the switching of the assigned archives work, by using the "wpv_filter_force_wordpress_archive" filter:

To achieve this, you can create one archive, let's call it 'Archive A' that will be shown to everyone, and set it to be assigned to the desired items under the "Loop selection" settings.

Next, you can create another archive, let's call it 'Archive B', that will be shown to only 'administrator' and 'shop_manager' roles, but you'll not assign it to any item under the "Loop selection" settings.

After that, the custom function attached to the "wpv_filter_force_wordpress_archive" filter can check if the current user is either 'administrator' or 'shop_manager' and if the condition is true, change the assigned archive to "Archive B", for that user only:

add_filter( 'wpv_filter_force_wordpress_archive', 'custom_archive_switch_func', 30, 2 );
function custom_archive_switch_func( $wpa_assigned, $wpa_loop ) {
	// currently assigned archive
	$wpa_to_apply = $wpa_assigned;
	// if visitor is logged in
	if( is_user_logged_in() ) {
		// get current user's role
		$user = wp_get_current_user();
		$roles = ( array ) $user->roles;
		//if user has 'administrator' or 'shop_manager' role
		if ( (in_array('administrator', $roles)) || (in_array('shop_manager', $roles)) ) {
		// set a different archive
			$wpa_to_apply = '12345';
	return $wpa_to_apply;

Note: Please replace '12345' with the actual archive ID that you've created for the 'administrator' or 'shop_manager' roles.

The above code snippet can be included through either Toolset's custom code feature ( ref: ) or through the active theme's "functions.php" file.

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