Skip Navigation

[Resolved] types_render_field not being used by PHP variable as expected

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

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

Last updated by aeroventA 3 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1988297

Tell us what you are trying to do?
From a WP-Query get custom post type ad get value of custom field and save value to a variable

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

I have a WP_Query that gets custom post type call "fan-type" and then gets related custom post "fan" based on the ID for "fan-type" custom post type. That is all working as expected.
I thne use the "fan" custom post type to get the custom field data for that post but it is not working correctly.

Below is a copy of my code where you can see that I am saving the types_render_field to seperate Variables and then using those variables to create an object call "$oFanTmp"

When I var_dump the object none of the custom field values are in the correct place.

You can try it out at here so you can see what I mean:
hidden link

Thanks for your help.

// ###### SELECT FANS SELECTED FROM TOOLSET #########

//Use selection details to pull fans from TOOLSET

//get Toolet custom post type fan
$meta_array=array('relation' => 'OR',);
foreach ($mountingType as $key => $value){
array_push($meta_array,
array('key' => 'wpcf-fan-type-mounting-type',
'value' => $value ,
'compare' => '=',)
);
}
$args = array(

'post_type' => 'fan-type',
'meta_query'=>$meta_array
); //end args

// Call WP_Query and load the content from the database
$my_query = new WP_Query($args);

if ( $my_query->have_posts() ) :

while ( $my_query->have_posts() ) : $my_query->the_post();

//get the ID of the mounting type post
$fanTypeFields = get_the_ID();

//get the fans that relates to mounting type post
$fanfields = toolset_get_related_posts($fanTypeFields,'fan-type-fan',['query_by_role' => 'parent']);

//get the fan series with the fan type ID
$fanSeriesFields = toolset_get_related_posts(['child'=>$fanTypeFields],'fan-series-fan-type',['role_to_return'=>'parent']);

foreach($fanfields as $fanfield){
// get values of custom post fields from toolset using the fan post type ID

//from fan post type
$model = types_render_field('fan-model',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanGroup = types_render_field('fan-fan-group',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$price = types_render_field('fan-price',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanMotorId = types_render_field('fan-motor-id',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanImpellerId = types_render_field('fan-impeller-id',array('post_id'=>$fanfield,'output' => 'raw'));
$isLimitCurve = types_render_field('fan-is-limit-curve',array('post_id'=>$fanfield,'output' => 'raw'));
$fanEndX1 = types_render_field('fan-end-x1',array('post_id'=>$fanfield,'output' => 'raw'));
$fanEndY1 = types_render_field('fan-end-y1',array('post_id'=>$fanfield,'output' => 'raw'));
$fanEndX2 = types_render_field('fan-end-x2',array('post_id'=>$fanfield,'output' => 'raw'));
$fanEndY2 = types_render_field('fan-end-y2',array('post_id'=>$fanfield,'output' => 'raw'));
$PolyPoints = types_render_field('fan-poly-points',array('post_id'=>$fanfield,'output' => 'raw'));
$fanImpellerOptions = types_render_field('fan-impeller-options',array('post_id'=>$fanfield,'output' => 'raw'));
$NomFanSpeed = types_render_field('fans-nom-fan-speed',array('post_id'=>$fanfield,'output' => 'raw'));
$fanMotorOptions = types_render_field('fan-motor-options',array('post_id'=>$fanfield,'output' => 'raw'));
$fanDia = types_render_field('fan-dia',array('post_id'=>$fanfield,'output' => 'raw'));
$FanTypeID = types_render_field('fan-type-id',array('post_id'=>$fanfield,'output' => 'raw'));

$X = array();
$X0 = types_render_field('fan-x0',array('post_id'=>$fanfield,'output' => 'raw'));
$X1 = types_render_field('fan-x1',array('post_id'=>$fanfield,'output' => 'raw'));
$X2 = types_render_field('fan-x2',array('post_id'=>$fanfield,'output' => 'raw'));
$X3 = types_render_field('fan-x3',array('post_id'=>$fanfield,'output' => 'raw'));
$X4 = types_render_field('fan-x4',array('post_id'=>$fanfield,'output' => 'raw'));
$X5 = types_render_field('fan-x5',array('post_id'=>$fanfield,'output' => 'raw'));
$X6 = types_render_field('fan-x6',array('post_id'=>$fanfield,'output' => 'raw'));
$X7 = types_render_field('fan-x7',array('post_id'=>$fanfield,'output' => 'raw'));
$X8 = types_render_field('fan-x8',array('post_id'=>$fanfield,'output' => 'raw'));
$X9 = types_render_field('fan-x9',array('post_id'=>$fanfield,'output' => 'raw'));
$X10 = types_render_field('fan-x10',array('post_id'=>$fanfield,'output' => 'raw'));
$X11 = types_render_field('fan-x11',array('post_id'=>$fanfield,'output' => 'raw'));
$X12 = types_render_field('fan-x12',array('post_id'=>$fanfield,'output' => 'raw'));
$X13 = types_render_field('fan-x13',array('post_id'=>$fanfield,'output' => 'raw'));
$X14 = types_render_field('fan-x14',array('post_id'=>$fanfield,'output' => 'raw'));
$X15 = types_render_field('fan-x15',array('post_id'=>$fanfield,'output' => 'raw'));

//push values onto $X array
$X=[$X0,$X1,$X2,$X3,$X4,$X5,$X6,$X7,$X8,$X9,$X10,$X11,$X12,$X13,$X14,$X15];

//from Impeller post type
$fandBA = types_render_field('dba-3m',array('post_id'=>$fanfield,'output' => 'raw', 'item'=>@'impellers-fan.parent'));
$fanImpeller = types_render_field('impeller',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impellers-fan.parent'));

//from the motor post type
$fankW = types_render_field('motor-kw',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$fanAmps = types_render_field('motor-amps',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$powerSupply = types_render_field('motor-phase',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$fanActFanSpeed = types_render_field('motor-rpm',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$MaxBoreDia = types_render_field('impeller-kw-max-bore-dia',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));

//From the fan series post type
$vpFactor = types_render_field('fan-series-vp-factor',array('post_id'=>$fanSeriesFields,'output' => 'raw'));
$HasDetailedNoiseData = types_render_field('fan-series-has-detailed-noise-data',array('post_id'=>$fanSeriesFields,'output' => 'raw'));

//from fan types post type
$fanTypeImage = types_render_field('fan-type-image',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));
$fanTypeShortDesc = types_render_field('fan-type-short-desc',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));
$fanSeries = types_render_field('fan-type-fan-series',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));

//from impeller kw post type
$kw_PolyPoints = types_render_field('impeller-kw-polypoints',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));

$kw_X = array();
$kw_X0 = types_render_field('impeller-kw-x0',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X1 = types_render_field('impeller-kw-x1',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X2 = types_render_field('impeller-kw-x2',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X3 = types_render_field('impeller-kw-x3',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X4 = types_render_field('impeller-kw-x4',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X5 = types_render_field('impeller-kw-x5',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X6 = types_render_field('impeller-kw-x6',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X7 = types_render_field('impeller-kw-x7',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X8 = types_render_field('impeller-kw-x8',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X9 = types_render_field('impeller-kw-x9',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));

//push values onto $kw_X array
$kw_X=[$kw_X0,$kw_X1,$kw_X2,$kw_X3,$kw_X4,$kw_X5,$kw_X6,$kw_X7,$kw_X8,$kw_X9];

//oFanTmp
$oFanTmp = new selected_fan_fan_find(

//From the fan post type
$oFanTmp->model = $model,
$oFanTmp->fanGroup = $fanGroup,
$oFanTmp->price = $price,
$oFanTmp->fanMotorId = $fanMotorId,
$oFanTmp->fanImpellerID = $fanImpellerId,
$oFanTmp->IsLimitCurve = $isLimitCurve,
$oFanTmp->fanEndX1 = $fanEndX1,
$oFanTmp->fanEndY1 = $fanEndY1,
$oFanTmp->fanEndX2 = $fanEndX2,
$oFanTmp->fanEndY2 = $fanEndY2,
$oFanTmp->PolyPoints = $PolyPoints,
$oFanTmp->fanImpellerOptions = $fanImpellerOptions,
$oFanTmp->X = $X,
$oFanTmp->X0 = $X0,
$oFanTmp->X1 = $X1,
$oFanTmp->X2 = $X2,
$oFanTmp->X3 = $X3,
$oFanTmp->X4 = $X4,
$oFanTmp->X5 = $X5,
$oFanTmp->X6 = $X6,
$oFanTmp->X7 = $X7,
$oFanTmp->X8 = $X8,
$oFanTmp->X9 = $X9,
$oFanTmp->X10 = $X10,
$oFanTmp->X11 = $X11,
$oFanTmp->X12 = $X12,
$oFanTmp->X13 = $X13,
$oFanTmp->X14 = $X14,
$oFanTmp->X15 = $X15,
$oFanTmp->NomFanSpeed = $NomFanSpeed,
$oFanTmp->fanMotorOptions = $fanMotorOptions,
$oFanTmp->fanDia = $fanDia,
$oFanTmp->FanTypeID = $FanTypeID,

//from Impeller post type
$oFanTmp->fandBA = $fandBA,
$oFanTmp->fanImpeller = $fanImpeller,

//from the motor post type
$oFanTmp->fankW = $fankW,
$oFanTmp->fanAmps = $fanAmps,
$oFanTmp->powerSupply = $powerSupply,
$oFanTmp->fanActFanSpeed = $fanActFanSpeed,
$oFanTmp->MaxBoreDia = $MaxBoreDia,

//From the fan series post type
$oFanTmp->vpFactor = $vpFactor,
$oFanTmp->HasDetailedNoiseData = $HasDetailedNoiseData,

//from fan types post type
$oFanTmp->fanTypeImage = $fanTypeImage,
$oFanTmp->fanTypeShortDesc = $fanTypeShortDesc,
$oFanTmp->fanSeries = $fanSeries,

//from impeller kw post type
$oFanTmp->kw_PolyPoints = $kw_PolyPoints,
$oFanTmp->kw_X = $kw_X,
$oFanTmp->kw_X0 = $kw_X0,
$oFanTmp->kw_X1 = $kw_X1,
$oFanTmp->kw_X2 = $kw_X2,
$oFanTmp->kw_X3 = $kw_X3,
$oFanTmp->kw_X4 = $kw_X4,
$oFanTmp->kw_X5 = $kw_X5,
$oFanTmp->kw_X6 = $kw_X6,
$oFanTmp->kw_X7 = $kw_X7,
$oFanTmp->kw_X8 = $kw_X8,
$oFanTmp->kw_X9 = $kw_X9,
);
}//end foreach fanfields

var_dump($oFanTmp);
echo"<hr/><br/>";
//Array of all fans
$oAllFans=[$oFanTmp];

endwhile;

wp_reset_postdata();
endif;
return $oFanTmp;

#1988611

Hello,

There might be a problem in this line:

$fanfields = toolset_get_related_posts($fanTypeFields,'fan-type-fan',['query_by_role' => 'parent']);

You can simply add a line below it to debug its result, for example:

var_dump($fanfields);

Check if it outputs correct post IDs.

If not, you will need to follow our document to setup the PHP codes:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
Query related posts by a set of conditions.

#1991717

Hi,
Thanks for getting back to me. I have since modified my code and I am getting the correct post ID's with $fanfields
But I am still having problems with getting the values of the custom fields for the the $fanfields posts.
$fanfields was returing a multidimensional array of the fan post ID's so I have merged to a single dimension.
I am then using a foreach loop to loop through the array and get the custom fields for those posts and create an obeject with the vaules of those custom fields in the code below.

//loop through $fanfields multidimensional array and merge to single dimension
$result = [];
foreach($fanfields as $arr)
{
$result = array_merge($result , $arr);
}
echo"Fan ID's<br/>";
var_dump($result);
echo"<hr/><br/>";

//loop through fans to get customp post fields for the fans.
foreach($result as $fanfield){

// get values of custom post fields from toolset using the fan post type ID

//from fan post type
$model = types_render_field('fan-model',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanGroup = types_render_field('fan-fan-group',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$price = types_render_field('fan-price',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanMotorId = types_render_field('fan-motor-id',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanImpellerId = types_render_field('fan-impeller-id',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$isLimitCurve = types_render_field('fan-is-limit-curve',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndX1 = types_render_field('fan-end-x1',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndY1 = types_render_field('fan-end-y1',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndX2 = types_render_field('fan-end-x2',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndY2 = types_render_field('fan-end-y2',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$PolyPoints = types_render_field('fan-poly-points',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanImpellerOptions = types_render_field('fan-impeller-options',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$NomFanSpeed = types_render_field('fans-nom-fan-speed',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanMotorOptions = types_render_field('fan-motor-options',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanDia = types_render_field('fan-dia',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$FanTypeID = types_render_field('fan-type-id',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));

$X = array();
$X0 = types_render_field('fan-x0',array('post_id'=>$fanfield,'output' => 'raw'));
$X1 = types_render_field('fan-x1',array('post_id'=>$fanfield,'output' => 'raw'));
$X2 = types_render_field('fan-x2',array('post_id'=>$fanfield,'output' => 'raw'));
$X3 = types_render_field('fan-x3',array('post_id'=>$fanfield,'output' => 'raw'));
$X4 = types_render_field('fan-x4',array('post_id'=>$fanfield,'output' => 'raw'));
$X5 = types_render_field('fan-x5',array('post_id'=>$fanfield,'output' => 'raw'));
$X6 = types_render_field('fan-x6',array('post_id'=>$fanfield,'output' => 'raw'));
$X7 = types_render_field('fan-x7',array('post_id'=>$fanfield,'output' => 'raw'));
$X8 = types_render_field('fan-x8',array('post_id'=>$fanfield,'output' => 'raw'));
$X9 = types_render_field('fan-x9',array('post_id'=>$fanfield,'output' => 'raw'));
$X10 = types_render_field('fan-x10',array('post_id'=>$fanfield,'output' => 'raw'));
$X11 = types_render_field('fan-x11',array('post_id'=>$fanfield,'output' => 'raw'));
$X12 = types_render_field('fan-x12',array('post_id'=>$fanfield,'output' => 'raw'));
$X13 = types_render_field('fan-x13',array('post_id'=>$fanfield,'output' => 'raw'));
$X14 = types_render_field('fan-x14',array('post_id'=>$fanfield,'output' => 'raw'));
$X15 = types_render_field('fan-x15',array('post_id'=>$fanfield,'output' => 'raw'));

//push values onto $X array
$X=[$X0,$X1,$X2,$X3,$X4,$X5,$X6,$X7,$X8,$X9,$X10,$X11,$X12,$X13,$X14,$X15];

//from Impeller post type
$fandBA = types_render_field('dba-3m',array('post_id'=>$fanfield,'output' => 'raw', 'item'=>@'impellers-fan.parent'));
$fanImpeller = types_render_field('impeller',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impellers-fan.parent'));

//from the motor post type
$fankW = types_render_field('motor-kw',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$fanAmps = types_render_field('motor-amps',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$powerSupply = types_render_field('motor-phase',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$fanActFanSpeed = types_render_field('motor-rpm',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$MaxBoreDia = types_render_field('impeller-kw-max-bore-dia',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));

//From the fan series post type
$vpFactor = types_render_field('fan-series-vp-factor',array('post_id'=>$fanSeriesFields,'output' => 'raw'));
$HasDetailedNoiseData = types_render_field('fan-series-has-detailed-noise-data',array('post_id'=>$fanSeriesFields,'output' => 'raw'));

//from fan types post type
$fanTypeImage = types_render_field('fan-type-image',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));
$fanTypeShortDesc = types_render_field('fan-type-short-desc',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));
$fanSeries = types_render_field('fan-type-fan-series',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));

//from impeller kw post type
$kw_PolyPoints = types_render_field('impeller-kw-polypoints',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));

$kw_X = array();
$kw_X0 = types_render_field('impeller-kw-x0',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X1 = types_render_field('impeller-kw-x1',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X2 = types_render_field('impeller-kw-x2',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X3 = types_render_field('impeller-kw-x3',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X4 = types_render_field('impeller-kw-x4',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X5 = types_render_field('impeller-kw-x5',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X6 = types_render_field('impeller-kw-x6',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X7 = types_render_field('impeller-kw-x7',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X8 = types_render_field('impeller-kw-x8',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X9 = types_render_field('impeller-kw-x9',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));

//push values onto $kw_X array
$kw_X=[$kw_X0,$kw_X1,$kw_X2,$kw_X3,$kw_X4,$kw_X5,$kw_X6,$kw_X7,$kw_X8,$kw_X9];

//oFanTmp
$oFanTmp = new selected_fan_fan_find(

//From the fan post type
$oFanTmp->model = $model,
$oFanTmp->fanGroup = $fanGroup,
$oFanTmp->price = $price,
$oFanTmp->fanMotorId = $fanMotorId,
$oFanTmp->fanImpellerID = $fanImpellerId,
$oFanTmp->IsLimitCurve = $isLimitCurve,
$oFanTmp->fanEndX1 = $fanEndX1,
$oFanTmp->fanEndY1 = $fanEndY1,
$oFanTmp->fanEndX2 = $fanEndX2,
$oFanTmp->fanEndY2 = $fanEndY2,
$oFanTmp->PolyPoints = $PolyPoints,
$oFanTmp->fanImpellerOptions = $fanImpellerOptions,
$oFanTmp->X = $X,
$oFanTmp->X0 = $X0,
$oFanTmp->X1 = $X1,
$oFanTmp->X2 = $X2,
$oFanTmp->X3 = $X3,
$oFanTmp->X4 = $X4,
$oFanTmp->X5 = $X5,
$oFanTmp->X6 = $X6,
$oFanTmp->X7 = $X7,
$oFanTmp->X8 = $X8,
$oFanTmp->X9 = $X9,
$oFanTmp->X10 = $X10,
$oFanTmp->X11 = $X11,
$oFanTmp->X12 = $X12,
$oFanTmp->X13 = $X13,
$oFanTmp->X14 = $X14,
$oFanTmp->X15 = $X15,
$oFanTmp->NomFanSpeed = $NomFanSpeed,
$oFanTmp->fanMotorOptions = $fanMotorOptions,
$oFanTmp->fanDia = $fanDia,
$oFanTmp->FanTypeID = $FanTypeID,

//from Impeller post type
$oFanTmp->fandBA = $fandBA,
$oFanTmp->fanImpeller = $fanImpeller,

//from the motor post type
$oFanTmp->fankW = $fankW,
$oFanTmp->fanAmps = $fanAmps,
$oFanTmp->powerSupply = $powerSupply,
$oFanTmp->fanActFanSpeed = $fanActFanSpeed,
$oFanTmp->MaxBoreDia = $MaxBoreDia,

//From the fan series post type
$oFanTmp->vpFactor = $vpFactor,
$oFanTmp->HasDetailedNoiseData = $HasDetailedNoiseData,

//from fan types post type
$oFanTmp->fanTypeImage = $fanTypeImage,
$oFanTmp->fanTypeShortDesc = $fanTypeShortDesc,
$oFanTmp->fanSeries = $fanSeries,

//from impeller kw post type
$oFanTmp->kw_PolyPoints = $kw_PolyPoints,
$oFanTmp->kw_X = $kw_X,
$oFanTmp->kw_X0 = $kw_X0,
$oFanTmp->kw_X1 = $kw_X1,
$oFanTmp->kw_X2 = $kw_X2,
$oFanTmp->kw_X3 = $kw_X3,
$oFanTmp->kw_X4 = $kw_X4,
$oFanTmp->kw_X5 = $kw_X5,
$oFanTmp->kw_X6 = $kw_X6,
$oFanTmp->kw_X7 = $kw_X7,
$oFanTmp->kw_X8 = $kw_X8,
$oFanTmp->kw_X9 = $kw_X9,
);

$oAllFans=[$oFanTmp];
}//end foreach fanfields

//Array of all fans
echo"array of Fan objects<br/>";
var_dump($oAllFans);
echo"<hr/><br/>"; //loop through $fanfields multidimensional array and merge to single dimension
$result = [];
foreach($fanfields as $arr)
{
$result = array_merge($result , $arr);
}
echo"Fan ID's<br/>";
var_dump($result);
echo"<hr/><br/>";

//loop through fans to get customp post fields for the fans.
foreach($result as $fanfield){

// get values of custom post fields from toolset using the fan post type ID

//from fan post type
$model = types_render_field('fan-model',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanGroup = types_render_field('fan-fan-group',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$price = types_render_field('fan-price',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanMotorId = types_render_field('fan-motor-id',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanImpellerId = types_render_field('fan-impeller-id',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$isLimitCurve = types_render_field('fan-is-limit-curve',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndX1 = types_render_field('fan-end-x1',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndY1 = types_render_field('fan-end-y1',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndX2 = types_render_field('fan-end-x2',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanEndY2 = types_render_field('fan-end-y2',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$PolyPoints = types_render_field('fan-poly-points',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanImpellerOptions = types_render_field('fan-impeller-options',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$NomFanSpeed = types_render_field('fans-nom-fan-speed',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanMotorOptions = types_render_field('fan-motor-options',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$fanDia = types_render_field('fan-dia',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));
$FanTypeID = types_render_field('fan-type-id',array('post_id'=>$fanfield,'output' => 'raw','show_name'=>true));

$X = array();
$X0 = types_render_field('fan-x0',array('post_id'=>$fanfield,'output' => 'raw'));
$X1 = types_render_field('fan-x1',array('post_id'=>$fanfield,'output' => 'raw'));
$X2 = types_render_field('fan-x2',array('post_id'=>$fanfield,'output' => 'raw'));
$X3 = types_render_field('fan-x3',array('post_id'=>$fanfield,'output' => 'raw'));
$X4 = types_render_field('fan-x4',array('post_id'=>$fanfield,'output' => 'raw'));
$X5 = types_render_field('fan-x5',array('post_id'=>$fanfield,'output' => 'raw'));
$X6 = types_render_field('fan-x6',array('post_id'=>$fanfield,'output' => 'raw'));
$X7 = types_render_field('fan-x7',array('post_id'=>$fanfield,'output' => 'raw'));
$X8 = types_render_field('fan-x8',array('post_id'=>$fanfield,'output' => 'raw'));
$X9 = types_render_field('fan-x9',array('post_id'=>$fanfield,'output' => 'raw'));
$X10 = types_render_field('fan-x10',array('post_id'=>$fanfield,'output' => 'raw'));
$X11 = types_render_field('fan-x11',array('post_id'=>$fanfield,'output' => 'raw'));
$X12 = types_render_field('fan-x12',array('post_id'=>$fanfield,'output' => 'raw'));
$X13 = types_render_field('fan-x13',array('post_id'=>$fanfield,'output' => 'raw'));
$X14 = types_render_field('fan-x14',array('post_id'=>$fanfield,'output' => 'raw'));
$X15 = types_render_field('fan-x15',array('post_id'=>$fanfield,'output' => 'raw'));

//push values onto $X array
$X=[$X0,$X1,$X2,$X3,$X4,$X5,$X6,$X7,$X8,$X9,$X10,$X11,$X12,$X13,$X14,$X15];

//from Impeller post type
$fandBA = types_render_field('dba-3m',array('post_id'=>$fanfield,'output' => 'raw', 'item'=>@'impellers-fan.parent'));
$fanImpeller = types_render_field('impeller',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impellers-fan.parent'));

//from the motor post type
$fankW = types_render_field('motor-kw',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$fanAmps = types_render_field('motor-amps',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$powerSupply = types_render_field('motor-phase',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$fanActFanSpeed = types_render_field('motor-rpm',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));
$MaxBoreDia = types_render_field('impeller-kw-max-bore-dia',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'motor-fan.parent'));

//From the fan series post type
$vpFactor = types_render_field('fan-series-vp-factor',array('post_id'=>$fanSeriesFields,'output' => 'raw'));
$HasDetailedNoiseData = types_render_field('fan-series-has-detailed-noise-data',array('post_id'=>$fanSeriesFields,'output' => 'raw'));

//from fan types post type
$fanTypeImage = types_render_field('fan-type-image',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));
$fanTypeShortDesc = types_render_field('fan-type-short-desc',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));
$fanSeries = types_render_field('fan-type-fan-series',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'fan-type-fan.parent'));

//from impeller kw post type
$kw_PolyPoints = types_render_field('impeller-kw-polypoints',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));

$kw_X = array();
$kw_X0 = types_render_field('impeller-kw-x0',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X1 = types_render_field('impeller-kw-x1',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X2 = types_render_field('impeller-kw-x2',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X3 = types_render_field('impeller-kw-x3',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X4 = types_render_field('impeller-kw-x4',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X5 = types_render_field('impeller-kw-x5',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X6 = types_render_field('impeller-kw-x6',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X7 = types_render_field('impeller-kw-x7',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X8 = types_render_field('impeller-kw-x8',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));
$kw_X9 = types_render_field('impeller-kw-x9',array('post_id'=>$fanfield,'output' => 'raw','item'=>@'impeller-kw-fan.parent'));

//push values onto $kw_X array
$kw_X=[$kw_X0,$kw_X1,$kw_X2,$kw_X3,$kw_X4,$kw_X5,$kw_X6,$kw_X7,$kw_X8,$kw_X9];

//oFanTmp
$oFanTmp = new selected_fan_fan_find(

//From the fan post type
$oFanTmp->model = $model,
$oFanTmp->fanGroup = $fanGroup,
$oFanTmp->price = $price,
$oFanTmp->fanMotorId = $fanMotorId,
$oFanTmp->fanImpellerID = $fanImpellerId,
$oFanTmp->IsLimitCurve = $isLimitCurve,
$oFanTmp->fanEndX1 = $fanEndX1,
$oFanTmp->fanEndY1 = $fanEndY1,
$oFanTmp->fanEndX2 = $fanEndX2,
$oFanTmp->fanEndY2 = $fanEndY2,
$oFanTmp->PolyPoints = $PolyPoints,
$oFanTmp->fanImpellerOptions = $fanImpellerOptions,
$oFanTmp->X = $X,
$oFanTmp->X0 = $X0,
$oFanTmp->X1 = $X1,
$oFanTmp->X2 = $X2,
$oFanTmp->X3 = $X3,
$oFanTmp->X4 = $X4,
$oFanTmp->X5 = $X5,
$oFanTmp->X6 = $X6,
$oFanTmp->X7 = $X7,
$oFanTmp->X8 = $X8,
$oFanTmp->X9 = $X9,
$oFanTmp->X10 = $X10,
$oFanTmp->X11 = $X11,
$oFanTmp->X12 = $X12,
$oFanTmp->X13 = $X13,
$oFanTmp->X14 = $X14,
$oFanTmp->X15 = $X15,
$oFanTmp->NomFanSpeed = $NomFanSpeed,
$oFanTmp->fanMotorOptions = $fanMotorOptions,
$oFanTmp->fanDia = $fanDia,
$oFanTmp->FanTypeID = $FanTypeID,

//from Impeller post type
$oFanTmp->fandBA = $fandBA,
$oFanTmp->fanImpeller = $fanImpeller,

//from the motor post type
$oFanTmp->fankW = $fankW,
$oFanTmp->fanAmps = $fanAmps,
$oFanTmp->powerSupply = $powerSupply,
$oFanTmp->fanActFanSpeed = $fanActFanSpeed,
$oFanTmp->MaxBoreDia = $MaxBoreDia,

//From the fan series post type
$oFanTmp->vpFactor = $vpFactor,
$oFanTmp->HasDetailedNoiseData = $HasDetailedNoiseData,

//from fan types post type
$oFanTmp->fanTypeImage = $fanTypeImage,
$oFanTmp->fanTypeShortDesc = $fanTypeShortDesc,
$oFanTmp->fanSeries = $fanSeries,

//from impeller kw post type
$oFanTmp->kw_PolyPoints = $kw_PolyPoints,
$oFanTmp->kw_X = $kw_X,
$oFanTmp->kw_X0 = $kw_X0,
$oFanTmp->kw_X1 = $kw_X1,
$oFanTmp->kw_X2 = $kw_X2,
$oFanTmp->kw_X3 = $kw_X3,
$oFanTmp->kw_X4 = $kw_X4,
$oFanTmp->kw_X5 = $kw_X5,
$oFanTmp->kw_X6 = $kw_X6,
$oFanTmp->kw_X7 = $kw_X7,
$oFanTmp->kw_X8 = $kw_X8,
$oFanTmp->kw_X9 = $kw_X9,
);

$oAllFans=[$oFanTmp];
}//end foreach fanfields

//Array of all fans
echo"array of Fan objects<br/>";
var_dump($oAllFans);
echo"<hr/><br/>";

In the var_dump of the object is has the incorrect values as shown here:
The "model" and "fanGroup" are correct but it in "fanImpellerOptions" it is showing the fan price and in "fanImpeller" it is showing the fan motor ID.
It has me really confused as to why it is showing the incorrect fields.

array(1) { [0]=> object(selected_fan_fan_find)#13115 (53) { ["model"]=> string(23) "Fan model: PE031-201-02" ["fanGroup"]=> string(19) "fan fan group: 4500" ["fanImpellerOptions"]=> string(14) "fan price: 435" ["fanImpeller"]=> string(26) "fan motor ID: PE031-201-02" ["fanImpellerID"]=> string(29) "fan Impeller ID: PE031-201-02" ["fanMotorOptions"]=> string(21) "fan is limit curve: 0" ["fanMotorId"]=> string(23) "fan end X1: 0.002084084" ["fandBA"]=> string(20) "fan end Y1: 765.2439" ["fankW"]=> string(22) "fan end X2: 0.63564565" ["fanAmps"]=> string(21) "fan end Y2: 3.0487805" ["fanActFanSpeed"]=> string(18) "fan poly points: 4" ["NomFanSpeed"]=> string(0) "" ["price"]=> array(16) { [0]=> string(9) "769.86768" [1]=> string(10) "-2061.3547" [2]=> string(9) "2510.2477" [3]=> string(10) "-1833.2641" [4]=> string(1) "0" [5]=> string(1) "0" [6]=> string(1) "0" [7]=> string(1) "0" [8]=> string(1) "0" [9]=> string(1) "0" [10]=> string(1) "0" [11]=> string(1) "0" [12]=> string(1) "0" [13]=> string(1) "0" [14]=> string(1) "0" [15]=> string(1) "0" } ["powerSupply"]=> string(9) "769.86768" ["fanDia"]=> string(10) "-2061.3547" ["fanSeries"]=> string(9) "2510.2477" ["fanTypeShortDesc"]=> string(10) "-1833.2641" ["vpFactor"]=> string(1) "0" ["fanEndX1"]=> string(1) "0" ["fanEndY1"]=> string(1) "0" ["fanEndX2"]=> string(1) "0" ["fanEndY2"]=> string(1) "0" ["PolyPoints"]=> string(1) "0" ["IsLimitCurve"]=> string(1) "0" ["HasDetailedNoiseData"]=> string(1) "0" ["X0"]=> string(1) "0" ["X1"]=> string(1) "0" ["X2"]=> string(1) "0" ["X3"]=> string(1) "0" ["X4"]=> string(24) "fans nom fan speed: 2800" ["X5"]=> string(21) "fan motor options: -1" ["X6"]=> string(12) "fan dia: 315" ["X7"]=> string(31) "fan type ID: In-line Mixed Flow" ["X8"]=> string(0) "" ["X9"]=> string(0) "" ["X10"]=> string(0) "" ["X11"]=> string(0) "" ["X12"]=> string(0) "" ["X13"]=> string(0) "" ["X14"]=> string(0) "" ["X15"]=> string(0) "" ["kw_PolyPoints"]=> string(0) "" ["kw_X0"]=> string(0) "" ["kw_X1"]=> string(0) "" ["kw_X2"]=> string(0) "" ["kw_X3"]=> string(0) "" ["kw_X4"]=> array(10) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(0) "" [4]=> string(0) "" [5]=> string(0) "" [6]=> string(0) "" [7]=> string(0) "" [8]=> string(0) "" [9]=> string(0) "" } ["kw_X5"]=> string(0) "" ["kw_X6"]=> string(0) "" ["kw_X7"]=> string(0) "" ["kw_X8"]=> string(0) "" ["kw_X9"]=> string(0) "" ["MaxBoreDia"]=> string(0) "" } }

Thanks so much for your help with this.

#1991719

My issue is resolved now. Thank you!
I realised it had to do with how I had created my object, nothing to do with Toolset.