I have a Wordpress post meta that has multiple arrays like this.
$costdata = Array(
Array( 'cost_id' => 1, 'cost_category' => 'Travel', 'cost_amount' => '3540')
Array( 'cost_id' => 2, 'cost_category' => 'Materials', 'cost_amount' => '1644')
Array( 'cost_id' => 3, 'cost_category' => 'Travel', 'cost_amount' => '1800')
);
add_post_meta($project_id, 'costdata', $costdata);
What I want to do is to get all 'cost_amount' where 'cost_category' is "Travel"
This is what I've done so far. I get a blank value. No error.
$listtravelcost = get_post_meta($project_id, 'costdata');
/*Calculate Travel cost */
$found_Travel = array_search('Travel', array_column($listtravelcost, 'cost_category'));
$travelbudget = array_column($found_Travel, 'cost_amount');
$printtravelbudget = array_sum($travelbudget);
echo $printtravelbudget;