I created my content template for displaying single listings using Divi. I have one section with a two-column row filled with code modules that include Toolset shortcodes. I have one module that includes a conditional that permits admins and editors to view edit and delete listing links.
I do not know how to make add a conditional to the Divi content template that performs the following ....
If a single listing property status is "archived" and the user is not an "Administrator" or "Editor", do not display the single listing.
Here's the conditional tag I created ....
[wpv-conditional if="[wpv-conditional if="( CONTAINS(#(status),'archived') AND ( '[wpv-current-user info='role']' eq 'Administrator' ) OR ( '[wpv-current-user info='role']' eq 'Editor' )[/wpv-conditional]
However, I still need an Administrator or Editor to see the single listing no matter if the Status is "archived" or "published"
A first parent condition can check whether the content has archived status or not and if that is true, the inner condition can check whether the current user's role is administrator or editor:
[wpv-conditional if="( CONTAINS(#(status),'archived') )"]
[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'editor' )"]
this archive content should only be visible to admin or editor
[/wpv-conditional]
[/wpv-conditional]
I hope this helps and please let me know if you need any further assistance around this.
Thank you. However, I still do not know where to place the conditional in my content template Divi layout. Also, I cannot add any Fields and Views into a Divi text module. When I click on insert shortcode, the shortcode does not get added. 🙁
When the shortcode doesn't get added, do you see any warning or error message in the browser's console or on the screen?
To troubleshoot this, I'll suggest the following steps:
1. Please make sure that WordPress, active theme, and plugins are all updated to the latest versions.
2. It would be interesting to test this with all non-Toolset plugins disabled.
If it's fixed, you can start adding the disabled items, one-by-one, to narrow down to a possible conflicting one.
3. In case the issue still persists, I'll need to see exactly how this Divi template is set up in the admin area. You're welcome to share temporary admin login details along with the link to a page with this content template.
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
I have tried it several times, open URL /spm-login, I see a WP login window, fill and submit the login form with the credentials you provided, I see the same error message: Your access to this site has been temporarily limited by the site owner
You can create a new content template and name it something like "Single Listing (archived)". You don't have to assign this content template to any post type or page and it will just include the message that you'd like to show when someone other than an admin or editor views the archived single listing page.
Suppose that the ID of the regular "Single Listing" content template is "123" and the ID of the new "Single Listing (archived)" content template is "456", then the code for the "wpv_filter_force_template" filter will look like this:
add_filter( 'wpv_filter_force_template', 'dynamic_template_override_listings', 99, 3 );
function dynamic_template_override_listings( $template_selected, $id, $kind ) {
if ( $template_selected == 123 ) { // assigned template is the one that we need to target
// check if archived
if( has_term( 'archived', 'status' ) ) {
// get current user's role
$user_role = do_shortcode('[wpv-current-user info="role"]');
// if current user's role is not administrator or editor, override the default template
if ( ($user_role != 'administrator') && ($user_role != 'editor') ) {
$template_selected = 456;
}
}
}
return $template_selected;
}
Note: Please replace the content template IDs with the actual ones from your website.
After that, for "Publish" listings the regular "Single Listing" content template will be used, but for the "Archived" listings the "Single Listing (archived)" content template will be forced (except for admins and editors).
I hope this helps and please let me know if you need any further assistance around this.