Skip Navigation

[Resolved] Display currently viewed user info outside loop

This support ticket is created 8 years, 5 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 2.21 hours from now. Thank you for your understanding.

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

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 34 replies, has 5 voices.

Last updated by Adriano 8 years ago.

Assisted by: Adriano.

Author
Posts
#344548

I am trying to: create a loop that displays on the currently viewed users posts (not the logged in users posts)

Example:
Logged in user id = x
Currently viewed user id = y

(Filter for views)
Select posts with custom field:
User-ID is a string equal to VIEW_PARAM(currentid)

How do I set currentid = y or get the value of 'y' outside the loop?

Thanks

#344766

andreyK-2
Supporter

Can you please elaborate a little more so I can better understand ? Sometimes screenshots illustrating what you mean may go a long way to clarify what words fail to transmit so if you like make use of "upload an image" below the comment area.

What exactly you are looking for ? How you wants to display the things ?

#344886
views-screenshot.png

This is the code that I have inserted into the page.
[wpv-view name="Bookings view" currentid="[get_userid]"]

I need to find a way to get_userid of the currently viewed user (not the logged in user)
so that I can filter the posts. I have tried using wpv-user but that only works in the loop.

"If the shortcode is inside a Views user query, it will display information for the user found in loop. Otherwise it will display information for the current logged-in user or the user with the specific id, when id attribute is set."

I have attached a screen shot as requested.

#344965

andreyK-2
Supporter

Could you please try to use following shortcode:
[wpv-attribute name="currentid"]

It should get the id of "currentid" which you pass to a view as attribute.

Please refer to the following documentation that may help you:
=> https://toolset.com/documentation/views-shortcodes/#wpv-attribute
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#345020

Thanks for your reply.

[wpv-attribute] allows me to pass a value into the loop from outside the loop (outside -> inside). I need to do it in the opposite direction.

I worked out a solution with shortcode that lets me get the value of the current viewed user profile. The problem is now that when I user that shortcode in the

[wpv-view name="Bookings view" currentid="[my_shortcode]"]

it breaks.

It works fine if I insert a number manually.

[wpv-view name="Bookings view" currentid="5"]

I realise this is another issue so should I open a different support ticket?

#345054

andreyK-2
Supporter
1.png

Have you registered your shortcode ?

If no, just Go to Views -> Settings and simply add them under the section Third-party shortcode arguments.

Have a look here :
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/

#345261
registered-shortcode.jpg
shortcode-in-shortcode.jpg
shortcode-replaced-by-number.jpg
result-replaced-by-number.jpg
result-shortcode-in-shortcode.jpg

Thanks for your reply.

I have already registered my shortcode. Still no luck. Shortcode code:

add_shortcode('get_useridx','get_userid');
function get_userid() {
	global $upme_api;
	$user_id = $upme_api->user_profile_id();
	return($user_id);
}

Code on page:

Current logged in user: [wpv-user field="ID"]
User ID of profile being viewed: [get_useridx]
---------
[toolset_access role="Freelancer" operator="deny"][wpv-view name="Bookings view" currentid="[get_useridx]"][/toolset_access]

Screenshots attached of code with results.

#345270

andreyK-2
Supporter

We've released not while ago a new versions of Types and Views. Could you please update them to their latest versions and let me know about the results ?

The most recent versions you can find under your account here :
https://toolset.com/account/downloads/

#345272
versions.jpg

Latest versions already installed.

#345424

andreyK-2
Supporter

I need to request temporary access (wp-admin and FTP) to your site – preferably to a test site where the problem has been replicated if possible – in order to be of better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

#345703

andreyK-2
Supporter

I was trying to log in to your FTP, but it gives me "530 Login authentication failed".

Could you please check if credentials are correct ?

#345776

andreyK-2
Supporter

Thanks, I got the access details. I will take a look and update you here as soon as I know more.

#346067

andreyK-2
Supporter

I played with your site a bit and found out following :

When you use [get_useridx] inside the view shortcode it looks like that it doesn't give any value and the view shortcode just gives all results.

I created a new shortcode on your site which returns '5' as a value and registered it in the view settings. I've tested it and it works as expected. You can test this shortcode also it calls [fakeid] ([wpv-view name="Bookings view" currentid="[fakeid]"]).

I suspect that the issue with your shortcode which you need to debug. I can see that inside your shortcode you are using some functions from current theme or some plugin, maybe that's the cause.

#346352

The [get_useridx] shortcode works outside the wp-view shortcode (see shortcode-in-shortcode.jpg and result-shortcode-in-shortcode.jpg above). I also demonstrated that if I replaced the shortcode (in the wp-view shortcode) with a number it works.

So the conclusion I can see is:
[get_useridx] works on it's own but doesn't work when placed into the wp-view shortcode (result-replaced-by-number.jpg)

Is there anyone else that can take a look at this?

#346449

Since Andrey currently has a few days off, I will replace him here in the forum.
I hope this is OK for you.

I have to read through the entire thread and will get back at you ASAP.

Please expect my informations here in the forum.

Thank you for your patience.

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