I am making a function to parse a .csv file uploaded in a custom field of a custom post. The name of the custom phone and the field's name is plan_information . The problem is when I var_dump(get_post_meta($post_id, 'plan_information', TRUE)) , I get an empty string.
The code I use is the following:
add_action('publish_phone', 'parse_csv', '99', 2);
function parse_csv($post_id) {
global $post;
$csv_file = get_post_meta($post_id, 'plan_information', TRUE);
$csv_file = wp_get_attachment_url($csv_file);
$title = get_post_meta($post_id, 'manufacturer', TRUE);
$title .= ' '.get_post_meta($post_id, 'model', TRUE);
$title .= ' '.get_post_meta($post_id, 'memory', TRUE);
$url = get_bloginfo('wpurl').'/';
$csv_file = str_replace($url, ABSPATH, $csv_file);
if($csv_file && !$carriers) {
$fp = fopen($csv_file ,"r");
if($fp) {
fgetcsv($fp, 1000, ",");
while (($data = fgetcsv($fp, 1000, ",")) !== FALSE)
{
$new_carrier = array(
'post_title' => $title. ' '. $data[0] . ' ' . $data[3],
'post_status' => 'publish',
'post_type' => 'carrier'
);
$post_id = wp_insert_post($new_carrier);
add_post_meta($post_id, 'operator', $data[0], true);
add_post_meta($post_id, 'logo', $data[1], true);
add_post_meta($post_id, 'cost', $data[2], true);
add_post_meta($post_id, 'plan_name', $data[3], true);
add_post_meta($post_id, 'hero', $data[4], true);
add_post_meta($post_id, 'summary', $data[5], true);
add_post_meta($post_id, 'phone_id', $post_id, true);
}
}
fclose($fp);
}
}

publish_phonehook? Have you checked that your function gets called? – Stephen Harris Jun 9 '12 at 19:11$datacontain what you expect, and what doesadd_post_metareturn? – Stephen Harris Jun 9 '12 at 19:32wp_insert_posttriggerssave_post. – Stephen Harris Jun 9 '12 at 21:29