Navigation überspringen

[Gelöst] Show different post status for different users

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
I want to show all view results in a published status to all guest users.
On the same page, I want to show all view results in a pending status to administrator only.
I have thought of two ways of implementing this:

1) Use two different views in the same page with two different filters, one filtering for post status = published, and the other one for post status=pending. The problem I'm facing is that when I update a view's filter, it also updates the other view's filter on the same page.

2) Use the save view but dynamically change the post status filtering based on whether the user is admin or not. Problem is that I don't know how to do this.

Another solution I guess would be I filter both for Published and Pending status. Then in the view's logic, I put a condition to show the right post status to the right set of users. That should do, though my preference would have been two separate views.

Solution:
Regarding the option(1), I assume that you are building these views with Blocks, right? We recently had a similar case(views filters overwritten) and it will be fixed soon.
I'll suggest, putting each view in a separate content template(the content template must not be assigned to any post type). This way, the views' filters won't be overwritten across each other.

Regarding the option(2), this will require custom code, hooked to the wpv_filter_query filter and modifying the query arguments "post_status" accordingly.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

The 3rd option is not a good solution. Because the view query will always return all the posts, instead of returning just what is needed. And this can have a performance hit on the view/page.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created vor 4 Jahren, 10 Monaten. 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: Africa/Casablanca (GMT+01:00)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Noriko Sugiura vor 4 Jahren, 10 Monaten.

Assistiert von: Jamal.

Author
Artikel
#1718175

--Tell us what you are trying to do?--
I want to show all view results in a published status to all guest users.
On the same page, I want to show all view results in a pending status to administrator only.
I have thought of two ways of implementing this:

1) Use two different views in the same page with two different filters, one filtering for post status = published, and the other one for post status=pending. The problem I'm facing is that when I update a view's filter, it also updates the other view's filter on the same page.

2) Use the save view but dynamically change the post status filtering based on whether the user is admin or not. Problem is that I don't know how to do this.

Another solution I guess would be I filter both for Published and Pending status. Then in the view's logic, I put a condition to show the right post status to the right set of users. That should do, though my preference would have been two separate views.

--Is there any documentation that you are following?--
No

--Is there a similar example that we can see?--
No

--What is the link to your site?--
versteckter Link

Thank you

#1718225

Hello and thank you for contacting the Toolset support.

Regarding the option(1), I assume that you are building these views with Blocks, right? We recently had a similar case(views filters overwritten) and it will be fixed soon.
I'll suggest, putting each view in a separate content template(the content template must not be assigned to any post type). This way, the views' filters won't be overwritten across each other.

Regarding the option(2), this will require custom code, hooked to the wpv_filter_query filter and modifying the query arguments "post_status" accordingly.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

The 3rd option is not a good solution. Because the view query will always return all the posts, instead of returning just what is needed. And this can have a performance hit on the view/page.

I hope this answers your questions. Let me know if you still need assistance with any of the solutions.

#1718253

Thank you so much, Jamal.

Using two content templates did the trick.