Skip Navigation

[Closed] Creating Conditional for Displaying Listings

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
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
#1638869

Currently, we have views and content templates to display our frontend listings for the public and for admins. Admins can select a taxonomy "status" option for a listing. The options are "published" and "archived."

When an admin selects "published" the listing displays using the single listing view. If the listing is marked "archived" the listing is not viewable by the public but still accessible by an admin.

This works, but unfortunately, Google indexes all of the listings and will not remove an "archived" listing. When the public clicks on a Google "archived" listing, he or she can see the archived listing.

Currently, I have the following conditional set up to display, in red, that the listing is no longed available.

[wpv-conditional if="( CONTAINS(#(status),'archived') )"]
<h1 style="color: #FF0000; font-weight: 600;">THIS LISTING HAS EXPIRED. PLEASE DO NOT CONTACT THE AGENT. THANK YOU.</h1>
[/wpv-conditional]

How can I create a conditional for an "archived" listing to only display if the status is "archived" and an admin is viewing the listing? I believe I have to create a query filter for the single listing view. I just don't know what to select.

Thank you.

🙂 Eric

#1639099

How can I create a conditional for an "archived" listing to only display if the status is "archived" and an admin is viewing the listing?
Hello, are you talking about hiding the posts in the results of a View or hiding the single listing posts? I'm not quite clear, because you mentioned Query Filters, Content Templates and viewing the listing. Query Filters are used in a View to hide certain results based on specific filter criteria. However, you also mentioned Content Templates and viewing the listing, which usually are related to the single posts on your site. Let's discuss both.

Let's assume you need to display the results of a Toolset View based on two conditional criteria. One part is based on user role, and the other part is based on the taxonomy term(s) assigned to the post. In Views (or Blocks) unfortunately there are no Query filters available that correspond to the current User or the current User's role. Instead, you can use toolset_access shortcodes in the View's loop editor to display post content conditionally based on User role. In the following example, only Administrators will see the post title:

[toolset_access role="Administrator" operator="allow"]
  [wpv-post-title]
[/toolset_access]

We have documentation available here for configuring these shortcodes: https://toolset.com/documentation/user-guides/access-control/access-control-texts-inside-page-content/
Feel free to let me know if this doesn't make sense, or if you need help implementing Access shortcodes.

The second part of the conditional display depends on the term or terms assigned to the post, and this filtering can be accomplished by adding a Query Filter to the View. If you cannot see the Query Filter panel when you edit the View, scroll to the top right corner and click "Screen Options". You can activate the Query Filter panel here. Now you will add a new filter based on the status taxonomy, where the term assigned is any of the following, then choose the archived term.

The combination of this term Query Filter and Access shortcodes will help hide the results of a View depending on the two conditional criteria: status taxonomy term, and current User role.

Now let's assume you need to stop a non-admin User from seeing archived single Listing post if they click an archived listing link on Google or type the URL directly into their browser. If you want to hide the content from the single Listing post, you must add conditional HTML or a conditional block in the single Listing Content Template. This is where your conditional comes into play. You could use this conditional in the Content Template to show specific content for the archived posts.

[wpv-conditional if="( CONTAINS(#(status),'archived') )"]
  This content is archived!
[/wpv-conditional]

Or, you could wrap the entire contents of the template in a conditional that tests if the term "archived" is NOT associated with the post:

[wpv-conditional if="( CONTAINS(#(status),'archived') )" evaluate="false"]
  This content is not archived!
[/wpv-conditional]

If the term is associated with the post, then nothing will be displayed here.

Please let me know if you have questions about this.

The topic ‘[Closed] Creating Conditional for Displaying Listings’ is closed to new replies.