• Resolved katiehmbl

    (@katiehmbl)


    I need to restrict content based on a custom field that I created called HOA. I also have two different user levels. I need to limit certain information based on user levels. In some cases, level 1 and 2 can view the information. In other cases, only level 2 can view the information. Below is the code that I am using. It works for me if I just have it restrict with the HOA field. As soon as I add in the user levels, it does not show anything.

    [restricted no_message=’Yes’ block_logged_in=’No’ field_name=’HOA’ field_value=’coursey1′ level=’2′]Coursey test[/restricted]

    [restricted no_message=’Yes’ block_logged_in=’No’ field_name=’HOA’ field_value=’coursey1′ minimum_level=’1′ maximum_level=’2′]Coursey test 2[/restricted]

    • This topic was modified 7 years, 6 months ago by katiehmbl.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor etoilewebdesign

    (@etoilewebdesign)

    Hi Katie,

    The restricted shortcode conditions are AND conditions, not OR conditions. So, for example, in your first shortcode, someone would need to have the coursey1 value and be level 2. Are you sure you have users that match all of the criteria found in each of your shortcodes?

    Thread Starter katiehmbl

    (@katiehmbl)

    So there is no way to check that they have the HOA value of coursey1 and the user level or 1 or 2?

    Plugin Contributor etoilewebdesign

    (@etoilewebdesign)

    Yes, since the conditionals are AND, you could definitely do that. Your second shortcode would be closer to correct.

    block_logged_in is set to No by default, so you don’t need it in the shortcode.

    You also need to make sure that you use only either plain-text single or double quotes in your shortcode. WordPress can be finicky with this and, if your quotes have any kind of styling (like an apostrophe, for example), the shortcode attributes won’t work.

    So, if you only wanted people who had the value coursey1 for a custom field called HOA and who were also either level 1 or 2, then you’d want to use something like:

    [restricted field_name="HOA" field_value="coursey1" minimum_level="1" maximum_level="2"]Restricted content[/restricted]
    

    You need to make sure that you have a user that matches all these criteria. And you also need to make sure that you are using the correct type of custom field for this functionality (e.g. radio button type).

    Thread Starter katiehmbl

    (@katiehmbl)

    I appreciate your help. I am using the exact code that you have provided. My user has the field HOA set to coursey1 and their user level is 2. However, it is still telling me that the content is restricted.
    When I first made this, the field HOA was a short text field. Since your last response, I made it a radio button type to see if that helped solve the issue of it not working. It is still not functioning.

    Thread Starter katiehmbl

    (@katiehmbl)

    It is working now! Not sure what I did differently, but thank you for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Resctrict Content Based on Custom Field and Level’ is closed to new replies.