Skip Navigation

[Resolved] Further Assistance Needed for Conditional Output

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

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 12 replies, has 3 voices.

Last updated by Eric 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1664107

Please refer to closed ticket at https://toolset.com/forums/topic/creating-conditional-for-displaying-listings/

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"

I hope you can help. 🙂 Eric

#1664493

Waqar
Supporter

Languages: English (English )

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

Hi Eric,

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

It is possible to nest and/or combine the conditions as explained in this guide:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/nesting-and-combining-conditions/

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.

regards,
Waqar

#1667843

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. 🙁

#1668347

Waqar
Supporter

Languages: English (English )

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

Thanks for writing back.

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.

#1669389

Hello,

I have tried the credentials you provided above, I get below errors:
Your access to this site has been temporarily limited by the site owner

Please check it, make sure your test site is valid for test and debug, thanks

#1669391

The login URL is /spm-login

You will automatically get blocked if you use the standard /wp-login.php

🙂 Eric

#1669417

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

#1669981

I am sorry Luo. I reset the login page to hidden link

I also whitelisted your IP address. Please give that a try. 🙂 Eric

#1672215

Waqar
Supporter

Languages: English (English )

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

Hi Eric,

Luo will be on vacation this week, so I'll be resuming back on this ticket.

Can you please disable the GEO IP restriction during the course of this troubleshooting or whitelist my IP address: 72.255.36.152 too?

regards,
Waqar

#1672269

Done Waqar. Thank you. 🙂 Eric

#1672357

Waqar. The username is actually "Toolset"

#1673635

Waqar
Supporter

Languages: English (English )

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

Hi Eric,

Thank you for allowing access to the admin area.

I've noticed that the website has a content template "Single Listing" built with Divi builder to show single "Listings" post pages.

Wrapping the entire content of this content template in a conditional block would be tricky, so a better solution would be forcing a different content template conditionally, using "wpv_filter_force_template" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

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.

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

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.

regards,
Waqar

#1687729

Thank you Waqar. Your solution works! 🙂 Eric

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