Skip Navigation

[Resolved] trying to generate a shortcode from wordpress User(ID) in user loop

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

Problem:
trying to generate a shortcode from wordpress User(ID) in user loop

Solution:
You can use the [wpv-user] shortcode to get the User ID in user view loop.

For example:

[wpv-user field='ID']

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/trying-to-generate-a-shortcode-from-wordpress-userid-in-user-loop/#post-924557

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user

This support ticket is created 6 years, 4 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.

Our next available supporter will start replying to tickets in about 0.88 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 12 replies, has 2 voices.

Last updated by Minesh 6 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#922322

I wonder if you have some idea - perhaps I am approaching this the wrong way !

Tell us what you are trying to do?
I have a a view setup to show user profiles and I would like to generate a field called coworker from the wordpress user which will display a booking calendar

Is there any documentation that you are following?
not really but the other plugin software doc is here
hidden link

Is there a similar example that we can see?
the following outputs what I want
<div class="row">
<div class="col-sm-4">[wpv-user field="ID"]</div>
<div class="col-sm-4">[tb-calendar coworker="6"]</div>
</div>
but I would like to manually build the tb-calendar shortcode to be reflect the current Userid in the loop
e.g. so that [tb-calendar coworker="wpv-user field="ID""]
What is the link to your site?
just a test but hidden link

thanks

#922334

just a sample of the type of end result

hidden link

#922364

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I do not know that the calendar shortcode will accept the shortcode for attribute or not.

For example - Could you please try to use following shortcode:

[tb-calendar coworker="[wpv-user field='ID']"]
#922785

thank you that seems to work, although it seems to be much slower in rendering the calendar display ... so let me post here a question from the calendar developer, to I/we can decide this is a good solution as I am about to create a reliance on this shortcode and I expect there might be a better way to do it.

from TB Calendar developer
'... if I correctly understood, you need the shortcode (let’s say [tb-calendar coworker=”auto”] ) to automatically detect the WP User ID inside the loop and print a calendar for that user only, but could you please define such “loop”? ' '...I don’t know how the Toolset Views plugin works, so I need to know if it is “transparent” (i.e. I can use a standard WordPress function like get_current_user_id() to retrieve it). '

can you let me know how to describe the way this user archive loop (for want of a better way to describe it) works ?

thanks !

#922951

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Have you tried the following shortcode inside the view's loop?

 [tb-calendar coworker="auto"]

Does it works?

#923309

Sorry maybe the update was not clear I think the teambooking developer was simply floating an idea but asking toolset developers before implementing:

How the Toolset Views plugin works - If if it is “transparent” --- i.e. Can we use a standard WordPress function like get_current_user_id() to retrieve it.

but yes I tried to prove the point !

hidden link

explains things

for now [tb-calendar coworker="[wpv-user field='ID']"] is working ... but l would appreciate the opinion of a toolset developer as to the best way to achieve this without guessing; I am surprised imbedding one shortcode inside another works.

thanks

#923525

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

How the Toolset Views plugin works - If if it is “transparent” --- i.e. Can we use a standard WordPress function like get_current_user_id() to retrieve it.
=> Well, yes, you can use it but not directly. You should wrap the get_current_user_id() with custom shortcode and return the user ID and use this custom shortcode.

for now [tb-calendar coworker="[wpv-user field='ID']"] is working ... but l would appreciate the opinion of a toolset developer as to the best way to achieve this without guessing; I am surprised imbedding one shortcode inside another works.
==> Well - as said, [wpv-user field='ID'] shortcode will return the user ID. There is no guess work at all. This is confirmed and this is the way to use it.

You can find more information on the shortcode with the following link:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user

#923552

from teambooking developer

Well, nested shortcodes are supported by WordPress (recursively, so with a little slowdown). I’m pretty much surprised, though, that a shortcode not really “nested” but used as attribute of another shortcode actually works too… I don’t know if that is a WordPress undocumented feature or something that such Toolset plugin handles directly.

#923574

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - Toolset just returning the user ID based on the user shortcode passed to attribute. There is no harm in that.

If you do not want to use that - you should user another method where create a custom shortcode that returns the current user ID and use it. I do not have any other solution to offer you unfortunately.

#923797

I thought you guys wanted to work with other developers ? I was trying to find the best solution and one that's supported, as I am building a business dependency on it.

some final comments for you to comment on

'Well, nested shortcodes are supported by WordPress (recursively, so with a little slowdown). I’m pretty much surprised, though, that a shortcode not really “nested” but used as attribute of another shortcode actually works too… I don’t know if that is a WordPress undocumented feature or something that such Toolset plugin handles directly.'

#924132

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - In Views we are doing a preparsing to determine if the transformed shortcode contains a shortcode attribute and if we detect such attribute we run do_shortcode on it before proceeding with the top-level shortcode transformation so you can have value without having any issue.

This is what our Dev said and what you get is expected results. The solution I gave is the best one as it will not going to break.

#924428

thankyou - that's exactly the sort of information I have been looking for: you mean toolset will run the standard wordpress function do_shortcode .. https://developer.wordpress.org/reference/functions/do_shortcode/ ?
cheers

#924557

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - exactly, Views will be doing preparsing to determine if the transformed shortcode contains a shortcode attribute and
if we detect such
on that attribute (which contains the shortcode as attribute value) we run do_shortcode on it before proceeding with the top-level shortcode transformation so you can have value without having any issue.