Sauter la navigation

[Résolu] Split: View search and result how to get result to a file

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 6 années et 4 mois. 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)

Marqué : ,

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par rexJ-2 Il y a 6 années et 4 mois.

Assisté par: Luo Yang.

Auteur
Publications
#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