Skip Navigation

[Resolved] Split: View search and result how to get result to a file

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

Problem:

get_view_query_results(), seems that it only get an array of post records. How do i get Post_meta? Is it in foreach loop?

Solution:

This is a custom PHP codes problem, check the detail answer here:
https://toolset.com/forums/topic/split-view-search-and-result-how-to-get-result-to-a-file/#post-1088230

Relevant Documentation:

https://developer.wordpress.org/reference/functions/get_post_custom/

This support ticket is created 6 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 2 replies, has 2 voices.

Last updated by rexJ-2 6 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1088227

Think i ask questions one at a time:
1:

get_view_query_results() 

seems that it only get an array of post records. How do i get Post_meta? Is it in foreach loop and then insert

 $one = get_post_meta($post_id,'wpcf-talet', true); 

or is there an better syntax in toolset?

#1088230

Q1) How do i get Post_meta?
I assume you are going to get all custom fields value with only one PHP function, you can try wordpress function get_post_custom():
https://developer.wordpress.org/reference/functions/get_post_custom/
Retrieve post meta fields, based on post ID.

Q2) Is it in foreach loop and then insert ... or is there an better syntax in toolset?

Yes, it is in the loop, for example:

$filtered_posts = get_view_query_results( 2537 );
foreach ( $filtered_posts as $filtered_post ) {
$post_id = $filtered_post->ID; // here get the single post ID
$one = get_post_meta($post_id,'wpcf-talet', true); // get the custom field "talet" value
$two = get_post_meta($post_id, 'wpcf-talto', true);
...
}

And you can also use Types function to retrieve the field value, see our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/

for example:

$one = types_render_field('talet', array('post_id' => $post_id)); // get the custom field "talet" value
#1096409

ok i understand its a kind of iteration where i have to specify each item i want in the loop with get_post_meta. And then do something with the array. Thanks