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