Hello,
I would like to conditonally display some HTML code (text and a button) only if the current user created and owns a specific custom post type.
If he is in possession of the post type and only if he is the author, then this code should display.
What shortcodes will help me to achhieve this?
Do you mind showing me the approach?
Have a nice day.
Nicholas
Thank you for contacting Toolset Support. I am happy to help you with this.
Are you also looking for code for frontend post type creation or just if the user created a particular post type?
Hello Tia.
Thank your for helping me out.
Only if the current user created and owns the specific custom post, the (in this example) text and button should be visible to the author.
What would the conditional sentence look like?
Oh and I would like to have this condition inside a CT.
I've experimented with these two shortcodes from the shortcode reference site: https://toolset.com/documentation/views-shortcodes/#wpv-post-type, but without success.
-wpv-current-user
-wpv-post-type
Thank you for the clarification. Let me test a few things on my end and I will respond as soon as possible with feedback.
The two shortcodes you are looking for is wpv-user and wpv-post-author.
[wpv-conditional if="( '[wpv-user field="ID"]' eq '[wpv-post-author format="meta" meta="ID"]' )"]
Text and Button here.
[/wpv-conditional]
[wpv-user field="ID"]
https://toolset.com/documentation/views-shortcodes/#wpv-user
[wpv-post-author format="meta" meta="ID"]
https://toolset.com/documentation/views-shortcodes/#wpv-post-author
The format='meta' meta='ID' portion of the wpv-post-author shortcode is equivalent to what data you could get using WordPress native functions. Example get_currentuserinfo(): ID, user_login, user_firstname, etc.
Please let me know if this resolves your question or if it needs more investigation.
Hello Tia.
Unfortunately this didn't work for me.
Let me explain further.
So basically my html looks like this:
<div class="box">
<div class="box-header-right">
<p> Text </p>
<a href="#" class="button button-a-b">Edit/a>
</div>
[wpv-view name="farmer-ma-tab-1-bauernhofprofil" limit="1"]
</div>
Inside a CT I have a view. The view belongs to a custom post that the user can create and edit via CRED. If the user hasn't created a post yet I don't want to display the "Text" and "Edit" Button.
Only If the user hast created a post or let's say is in possession of a post then the text and the button should display.
I know that inside the the Loop output editor there is this shortcode [wpv-no-items-found][/wpv-no-items-found], that does exactly that. Now I am wondering if there a shortcode like that outside the Loop output editor that I can use inside a Content Template? What would the conditional sentence look like?
Thank your for your help.
Nicholas
Hello, Nicholas. Apologies for the late reply. We are normally closed on the weekends.
To make sure I understand you:
If the user hasn't created a post yet I don't want to display the "Text" and "Edit" Button.
1. Will the user be the sole author of this custom post type or will there be multiple authors?
2. Only if the user created ANY post at all, regardless of if they own the post or not, you want the text & edit button to display, correct?
Hello Tia.
No problem at all. 🙂
1. There will only be one author. Basically the post the user creates is his own profile. So on my site the custom post type is just called "user profile".
2. Yes that's correct. If the user hasn't created his profile yet the "text & edit button" should not display.
Please keep in mind that the conditional sentence is inside a content template and not inside a view. As shown below:
<div class="box">
<!--This part should be conditional based on the post type -->
<div class="box-header-right">
<p> Text </p>
<a href="#" class="button button-a-b">Edit/a>
</div>
<!--This part should be conditional based on the post type-->
[wpv-view name=profile" limit="1"]
</div>
Thank you for your help.
Thank you. I will be looking into this further.
Thank you Tia. I'll also keep you updated..
This isn't going to be doable in a content template as there is not shortcode to best represent what you are trying to do.
However, I currently have 3 options for you:
1. Create a View - (more performance intensive) filter posts by author and include conditional in case the author has no posts.
2. CRED - I'm not sure if it's too late with your set up but I encourage you to look into CRED forms to serve as the profile form:
https://toolset.com/home/cred/
https://toolset.com/documentation/user-guides/#cred-topics
3. WordPress Shortcode - Another alternative is using native WordPress functions in a shortcode:
https://codex.wordpress.org/Shortcode_API
Thanks Tia.
I was able to do it with jQuery.