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
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 ?
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.
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/
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?
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/
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.
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/
Latest versions already installed.
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.
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 ?
Thanks, I got the access details. I will take a look and update you here as soon as I know more.
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.
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?
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.