Skip Navigation

[Resolved] filter query where post author is NOT current logged in user

This support ticket is created 8 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 - -
15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 - -

Supporter timezone: Asia/Jerusalem (GMT+03:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Mattnet 7 years, 12 months ago.

Assisted by: Itamar.

Author
Posts
#386079

I am trying to: add a filter to show only posts that were NOT created by current logged in user

I visited this URL: n/a

I expected to see: n/a

Instead, I got: i can easily add a filter to show posts by current logged in user.

#386860

Itamar
Supporter

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

wpv-post-author_highlight.jpg
post-author_display-options.jpg
post-author_current-user.jpg
insert-conditional-shortcode.jpg
highlihgt_shortcode.jpg
dummy-text_highlight.jpg
current-user-info.jpg

Hello.

Thank you for contacting the Toolset support forum.

There is a way to achieve what you want to achieve, but it is not by using the filter section but by using a condition with [wpv-conditional] shortcode in the Lop output section of the view.

What is finally achieved should look like the following:

[wpv-conditional if="( '[wpv-post-author format='meta' meta='ID']' ne '[wpv-current-user info='id']' )"]Here all the Post information must be inserted. It will show only Posts, that are NOT created by the logged in user.[/wpv-conditional]

I will now describe the process of how to achieve that.
1. Go to the Loop Output section of your view.
2. Highlight what you want to condition between the <wpv-loop> and </wpv-loop> tags. Screenshot highlight_shortcode.jpg.
What you highlight can be a content template shortcode a field shortcode or the all loop content that you have there.
3. When highlighted press the conditional output button.
Screenshot highlight_shortcode.jpg.
4. On the Insert conditional shortcode popup window select 'Views Shortcodes' from the Data origin first value field and then from the second value field select 'wpv-post-author'.
5. In the Comparison field select "!=" (not equal to sign)
6. In the Value field write some dummy text (it will be switched later with a user field). Screenshot insert-conditional-shortcode.jpg
7. Press the Insert Shortcode button.
8. Highlight the [wpv-post-author] shortcode and press the Fields and Views button. Screenshot wpv-post-author_highlight.jpg
9. From the Fields and Views shortcodes popup window under Basic press the Post author button. Screenshot post-author_current-user.jpg
10. From the Post author popup window select Author metadata radio button and then choose Author ID from the Author metadata field and press the Insert shortcode button. Screenshot post-author_display-options.jpg
11. Highlight the dummy text and press Fields and Views button. Screenshot dummy-text_highlight.jpg
12. From the popup window under User basic data press the 'Current user info' button and under 'Information' choose the 'UserID' option and press the Insert shortcode button. Screenshot current-user-info.jpg
13. Save your view.
14. Insert your view where you want it to be and that should show only the post of the not logged in user.

In this way, many other conditionals can be achieved. The possibilities are almost endless.

Our developers inform me that this process may be simplified in the future. But I can not promise when that will be.

Please also take a look at our documentation about Conditional HTML Output in Views:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

Please let me know if the above solution works for you, I look forward to your reply!

Thanks,
Itamar.

#387082
2016-04-14.png
2016-04-14 (1).png

Well I've done that and it works. Thing is I am trying to display the results in a layout with 4 posts per row, where the loop is using index=1. index=other and index=4. The conditional output is on the content template itself so it is still returning a place for it even though it's hiding the result. So my result set is showing 2 posts in positions 2 and 3 instead positions 1 and 2 (left justified), because result 1 is a logged in user and the two others that aren't logged in users are showing directly after. See screen shot 2016-04-14.png below for how the three 'following collections' are arranged. This is from user 1's persective. The next image '2016-04-14(1).png' is from user 2's perspective. See how the 2 posts ar sitting in position's 2 & 3 and not in position 1 & 2? How can I correct that?

#388603

Itamar
Supporter

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

Glad to hear that it works now.
And I would like you to know that I've found another option to make this work.

1. Create a user view and check "Don't show current logged user".
2. Create a post View, and in the Query Filter set "Post author is set by the parent User View".
3. Insert the *post view*​ to the ​*user’s view*​ loop output.
4. Insert the ​*user view*​ to your Page where you want to see it.

I hope this option will help you as well with what you are trying to achieve.

As the original issue is resolved may I kindly ask you please to open a new ticket for your additional question and ​mark this thread as resolved?

Posting a new thread for each issue helps not only supporters to focus on one issue at once, but also enables other users to find solutions to their questions faster.

You will be able to choose me as your supporter for that next issue that you have or choose any other available supporter.

Please follow this link for our support request guidelines:
https://toolset.com/toolset-support-policy/#support-request-guidelines

Thank you for your understanding.

Thanks,
Itamar.

#394380

Thanks for the help.

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