Tell us what you are trying to do?
I want to output the custom fields of child posts in an array.
$postID = get_the_ID();
$query = new WP_Query( array(
'post_type' => 'financial', // This is the child post
'toolset_relationships' => array(
'role' => 'child',
'related_to' => $postID,
'relationship' => 'company-financial', // This is the Toolset slug relationship
),
));
while( $query -> have_posts() ) {
$query -> the_post();
$postID = get_the_ID();
$pageCF = get_post_custom( $postID );
$distributions = $pageCF[ 'wpcf-distributions' ]; // The custom field I want to output is wpcf-distributions
print_r( $distributions ); // This prints out Array ( [0] => 11.7 ) Array ( [0] => 23.8 ) Array ( [0] => 26.7 ) Array ( [0] => 46.9 ) Array ( [0] => 28.6 ) Array ( [0] => 29 ) Array ( [0] => 30.3 )
}
I want it to output in this format 11.7, 23.8, 26.7, 36.8, 28.6, 29, 30.3.
However, the result is structured in this format
Array ( [0] => 11.7 ) Array ( [0] => 23.8 ) Array ( [0] => 26.7 ) Array ( [0] => 46.9 ) Array ( [0] => 28.6 ) Array ( [0] => 29 ) Array ( [0] => 30.3 )
Hello,
For example, you can relace these lines from:
while( $query -> have_posts() ) {
$query -> the_post();
$postID = get_the_ID();
$pageCF = get_post_custom( $postID );
$distributions = $pageCF[ 'wpcf-distributions' ]; // The custom field I want to output is wpcf-distributions
print_r( $distributions ); // This prints out Array ( [0] => 11.7 ) Array ( [0] => 23.8 ) Array ( [0] => 26.7 ) Array ( [0] => 46.9 ) Array ( [0] => 28.6 ) Array ( [0] => 29 ) Array ( [0] => 30.3 )
}
To:
$distributions = array();
while( $query -> have_posts() ) {
$query -> the_post();
$postID = get_the_ID();
$pageCF = get_post_custom( $postID );
$distributions[] = $pageCF[ 'wpcf-distributions' ]; // The custom field I want to output is wpcf-distributions
}
print_r( $distributions );
More help:
hidden link
My issue is resolved now. Thank you!