I try to get a list for all posts of custom post type bedrijf
from all values of a custom field. This field is an array of values. However, when I try to output the custom fields, I get
Notice: Array to string conversion in ...
I have tried different approaches like foreach
, wp_pluck_list
, but so far, no success.
function make_list_regios(){
global $post;
$output = '<ul>';
$post_idees = new WP_Query(array('post_type' => 'bedrijf'));
$values = wp_list_pluck( $post_idees->posts, 'ID');
foreach( $values as $value ) {
$meta_values[] = get_post_meta( $value, 'elements', true );
$output .= '<li>'.$meta_values.'</li>';
}
return ($output);
}
add_shortcode('regios', 'make_list_regios');
When I print_r($values)
, it is an array of post_id
. When I print out $meta_values
, I get an array as follows:
Array ( [0] => [1] => Array ( [0] => groningen [1] => limburg ) [2] => [3] => [4] => Array ( [0] => noordholland [1] => zuidholland ) )
What I want to output is a full list of selected regions.