Skip Navigation

[Resolved] How to display different content to the post author

This thread is resolved. Here is a description of the problem and solution.

Problem:
What is the right way to display some content to most visitors to a post, but different content to the author of that post?

Solution:
Use conditional shortcodes that compare the post author and the currently logged in user, like so:

[wpv-conditional if="( '[wpv-post-author format='meta' meta='ID']' eq '[wpv-user field='ID']' )"]
<p>You! are the author of this post</p>
[/wpv-conditional]
 
[wpv-conditional if="( '[wpv-post-author format='meta' meta='ID']' eq '[wpv-user field='ID']' )" evaluate="false"]
<p>You are NOT the author of this post</p>
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 5 years, 11 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by francescoG-3 5 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1169018

I am trying to: I have created a view where if the post author and the user who see the post are the same, some content should be different.
The content that the users that not are the post author is a "button", generated by the "Front end PM" plugin shortcode, where the user clicking on it can send Private Messages to the author of post.
This is the shortcode

[fep_shortcode_message_to to="{current-post-author}" subject="Ciao {!{wpv-post-title}!}" text="" class="contact-profile"]

Link to a page where the issue can be seen: hidden link

I expected to see: When I click on the button I expected to open the message box with the post author as recipient.

Instead, I got: only the name of the user that see the page.

#1169454

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, I'm not sure from your question whether the problem is that the Front end PM plugin shortcode doesn't work as expected, or whether you need help with the Toolset conditional shortcodes to display different things to users depending on whether they are the post author or not (and the Front end PM shortcode just happens to be the content that should be conditionally shown).

#1169629

Hi Nigel,
I need help with the Toolset conditional shortcodes to display different things to users depending on whether they are the post author or not (and the Front end PM shortcode just happens to be the content that should be conditionally shown).

To display the content generated by the Front end PM shortcode I have used View. The View work fine and display what I need, when the post author and the visitor user are the same the Front end PM shortcode content si not displayed and if them are different the Front end PM shortcode content is displayed but, the value that it return is not what I expected because it is in the loop. When the shortcode is in the view loop, the receipt is the username of the user who see the post, instead I need that the receipt should be the post author, because when the shortcode is out of view loop work fine.

#1169748

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

So, the problem is that when you insert the Front end PM shortcode in the Loop Output section of a View the shortcode returns the wrong content (you are expecting it to display content for the post author, but it is displaying content for the currently logged-in user).

Is that a correct summary of the problem?

Can you describe your View? What is it querying, where is it inserted?

Does it work if you add the shortcode to a template that displays single posts? It shows content based upon the author of the post being viewed rather than for the current user?

#1169803
01.png

So, the problem is that when you insert the Front end PM shortcode in the Loop Output section of a View the shortcode returns the wrong content (you are expecting it to display content for the post author, but it is displaying content for the currently logged-in user). Is that a correct summary of the problem?
Yes it is correct.

Can you describe your View? What is it querying, where is it inserted? see the attached image n°1

Does it work if you add the shortcode to a template that displays single posts? It shows content based upon the author of the post being viewed rather than for the current user?
Yes It work fine, showing content based upon the author of the post, if I added the shortcode to a template that displays single posts, but without using View.

#1170435

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'll need to see this on your site, because I set up a test locally after installing the messaging plugin and it worked correctly.

I created a static page and set the post author to a different user, and I inserted the fep_shortcode_message_to shortcode you described earlier.

Visiting this page on the front-end and clicking the link, I could see that I was sending a message to the post author, as expected.

So I then created a View to display the same page (a View to display pages, with a Query Filter to specify this same page), and I included the same fep_shortcode_message_to shortcode in the template of the View output. I inserted this View onto a different page and tested it. Again, it correctly was sending the message to the author of the post (not to me, the logged-in user).

If you are seeing something different there must be something else involved, so it would help if I could see your site.

But before that, can you please confirm you still see the problem if you disable all non-Toolset plugins (except the messaging plugin) and use the twentyseventeen or twentynineteen themes.

Let me mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes.

Can you confirm which View this is, and where it is used?

#1170531

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I was trying to examine the content template used by the View ("Contatto e Favorito") but it is locked, being edited by another user.

Anyway, I don't understand the set up.

You say that the problem is that the message is being sent to the currently logged-in user rather than the post author.

But you insert this with a View that has a Query Filter to display a profile where the post author is the currently logged-in user ("L'autore del post è lo stesso dell'utente registrato").

So the post author and the currently logged-in user are the same thing.

#1170542

So, Now you can open the content template ("Contatto e Favorito").
What I need is to display the "Edit profile link to edit Form" when the post author and the currently logged-in user are the same thing, if they are different to display the content template ("Contatto e Favorito") where there is the Front End PM shortcode.

#1170629

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, so then it is a question of using the wpv-conditional shortcodes to compare the post author and the current user, like so:

[wpv-conditional if="( '[wpv-post-author format='meta' meta='ID']' eq '[wpv-user field='ID']' )"]
<p>You! are the author of this post</p>
[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-author format='meta' meta='ID']' eq '[wpv-user field='ID']' )" evaluate="false"]
<p>You are NOT the author of this post</p>
[/wpv-conditional]

Sorry it took a while to get there, the Front end PM plugin was a distraction.

#1170660

Ok, thanks.
So, I will not using View for my cases, but I will using the wpv-conditional shortcodes.

Other general question. If I follow this guide https://toolset.com/learn/how-to-create-a-messaging-system-with-toolset/ it permit me to create a messaging system like as Front End PM? So, the principal function that I need to do is that all user roles can read the private messages but only some selected user roles can reply to the messages. If yes, I'm thinking to use only Toolset without other plugins.

#1171152

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Reading through the documentation about the messenger system it is intended as a one-to-one messaging system, in that any conversation can only be between two people, so bear that in mind.

Only the person who initiates a conversation with another user can see and respond to messages.

You can use Access to control which roles are able to see and use the forms for initiating or replying to messages, so sending and receiving messages can be restricted to certain roles.

The system itself is fairly simple, and looking at the documentation it looks like it should be possible to modify how it works so that users other than the two people directly involved in the conversation are able to see replies if that is a requirement.

Still, that's a different issue than your original question. Developing modifications to the messaging system is outside the scope of support, but if you go down that route and you get stuck on some particular issue then you are welcome to open a new forum thread asking for help.

#1171218

Hi Nigel,
thanks for your reply, I think that I will use the toolset to create and managing the messaging system.

For the original question, My issue is resolved with this reply https://toolset.com/forums/topic/how-to-have-the-correct-value-from-the-loop/#post-1170629. Thank you!