Skip Navigation

[Resolved] Get value from inside loop

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

Problem: I have a View that shows an item by a particular author. The author's username is included as a URL parameter for filtering. Inside the loop I can access the author's information but I would like to access that same information outside the loop in another area of the page.

Solution: You can use the wpv-search-term parameter to access any URL parameter, then use that value to set the user_name attribute in a Types usermeta field shortcode:

[types usermeta='giving-embed-code' output='raw' user_name='[wpv-search-term param="church"]'][/types]

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 5 years, 8 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by mikeH-3 5 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1237852

I put this code inside a views loop:
[types usermeta='giving-embed-code' output='raw' user_is_author='true'][/types]

This is the filter for that view:
Select Items with the author's username determined by the URL parameter "church" eg. yoursite.com/page/?church=admin

When I view this page on the front, it does show the data for 'giving-embed-code' in the loop. But my problem is, I need that piece of data in another part of that page too, that isn't in the loop. Just on the same page (in a side panel). How do I retrieve it? It always needs to match the authors username of whatever post is showing in the loop.

Ideally I just need a shortcode I put into this other part of the page that will always retrieve this value. And that value changes based on which author's post in the view I am seeing, whether it's yoursite.com/page/?church=admin or yoursite.com/page/?church=parker

Hope that makes sense!

#1237889

You can use the wpv-search-term shortcode to access a URL parameter even outside the loop. So you could try using the Types field shortcode with the user_name property set by the same URL parameter, like this:

[types usermeta='giving-embed-code' output='raw' user_name='[wpv-search-term param="church"]'][/types]

https://toolset.com/documentation/customizing-sites-using-php/functions/

#1237983

Thanks for the reply.

So if I put that in a normal page, yes it works. But if I put it in my template php file, regardless of if I'm on yoursite.com/page/?church=admin or yoursite.com/page/?church=parker, it shows the same data for that field. Thoughts?

Actually, I placed your shortcode in a widget and placed that widget in my template file. That seemed to do the trick. Thanks much!

#1237984

My issue is resolved now. Thank you!

#1239626

I want to do the same for a custom post field and get the data from it outside of the view loop. How would I do that?

I have:
<?php echo do_shortcode('[types field="number" output="raw" ][/types]'); ?>

This code is in a template on the website and I need to pull the 'number' field from whatever the current post is in the loop on that page (I'm only showing 1 post at a time in my view). I can't get it to show though. Is this not possible?