Skip Navigation

[Resolved] Custom field outside loop

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1239627

Following up on https://toolset.com/forums/topic/get-value-from-inside-loop/

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 view 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?

#1239629

Hello,

I suggest you create another post view, with same filters as your previous post view, but display only the custom field "number", and you can display the new post view with Views PHP function: render_view(), see our document:
https://toolset.com/documentation/programmer-reference/views-api/#render_view

#1240672

I can't do it that way. How would I pass the custom field value of the current post to an outside php template also running on that page, but not in the loop?

#1240682

Why can't you do that way? please elaborate the problem with more details?

And there isn't such kind of built-in feature within Views plugin:
pass the custom field value of the current post to an outside php template also running on that page, but not in the loop

It needs custom codes, for example, you can create a custom shortcode, stores global PHP variable "my-var", and:
1) If it is insider View's loop, setup the "my-var" value as custom post field "number" value
2) If it is after and outsider view's loop, then display the "my-var" value

More help:
https://codex.wordpress.org/Function_Reference/add_shortcode