Skip Navigation

[Resolved] Control access in specific category archives

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

Our next available supporter will start replying to tickets in about 8.60 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1261219

"You can add Access conditionals to a WordPress Archive to control visibility of each post."
Ok, the "archives" are two particular categories: how can I add Access conditionals to this categories?!

#1261243

Let me make sure I understand. You want to apply Access conditionals in a WordPress Archive, but only for 2 specific taxonomy term archives, is that correct? If so, then you can use nested conditionals like this:


	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			
          [wpv-conditional if="( '[wpv-taxonomy-archive]' eq 'cat-slug-1' OR '[wpv-taxonomy-archive]' eq 'cat-slug-2' )"]
          this is cat slug 1 or cat slug 2
            [toolset_access role="Author" operator="deny"]<li>
				[wpv-post-link]
				[wpv-post-date]
			</li>[/toolset_access]
          [/wpv-conditional]
			
          [wpv-conditional if="( '[wpv-taxonomy-archive]' ne 'cat-slug-1' AND '[wpv-taxonomy-archive]' ne 'cat-slug-2' )"]
          this is not cat slug 1 or cat slug 2
            <li>
				[wpv-post-link]
				[wpv-post-date]
			</li>
          [/wpv-conditional]
		</wpv-loop>
	</ul>

The wpv-conditional statements test the current archive term slug. Then inside those conditionals you can apply the Access conditionals as needed.

#1261387
Schermata 2019-06-06 alle 17.14.10.jpg

Here I am.
I use "Articles Group" to filter 2 type of post for different user.

GROUP 1 - 10 post, visibile only to user role 1 and 2
GROUP 2 - 10 post, visibile only to user role 3

And this part works, "role 3" can't view post in group 1.

But... in the BLOG PAGE, all type of roles can view all the "preview" of the post. (image attached)

I add also 2 different categories of this 2 GROUPS (Comunicazioni Breda - Comunicazione Bremet), so maybe we can use the categories to filter the content...

#1261577

So your conditionals would look something like this:

[wpv-conditional if="( has_term('cat-slug-1', 'category'))"]
      this is cat slug 1
        [toolset_access role="Author" operator="allow"]<li>
            [wpv-post-link]
            [wpv-post-date]
        </li>[/toolset_access]
      [/wpv-conditional]
         
      [wpv-conditional if="( has_term('cat-slug-2', 'category'))"]
      this is cat slug 2
        [toolset_access role="Editor" operator="allow"]<li>
            [wpv-post-link]
            [wpv-post-date]
        </li>[/toolset_access]
      [/wpv-conditional]
#1261797

Ok, but...
Where i put this “conditional”?

#1261859

... and also, if I wanna allow more than 1 role, the code it's something like this?

[wpv-conditional if="( has_term('comunicazioni-breda', 'category'))"]
      this is cat slug 1
        [toolset_access role="administrator,editor,author,commerciale_altri_prodotti,commerciale_libro,commerciale_sezionali" operator="allow"]<li>
            [wpv-post-link]
            [wpv-post-date]
        </li>[/toolset_access]
      [/wpv-conditional]
          
      [wpv-conditional if="( has_term('comunicazioni-bremet', 'category'))"]
      this is cat slug 2
        [toolset_access role="administrator,editor,author,commerciale_bremet" operator="allow"]<li>
            [wpv-post-link]
            [wpv-post-date]
        </li>[/toolset_access]
      [/wpv-conditional]
#1264377

You put this conditional inside a WordPress Archive, inside the Loop. Use it to hide the loop's contents from certain Users. Yes, if you want to allow more than one role you can combine roles in a comma-separated list.