Hi! I’m trying to use with my site and have no luck added the code to the functions.php, have I missed something?? My code looks:
function hj_create_vCard( $post_id ) {
/*
* In production code, $slug should be set only once in the plugin,
* preferably as a class property, rather than in each function that needs it.
*/
$post_type = get_post_type($post_id);
// only update the agremiados custom post type on save
if ( "Agremiados" != $post_type ) return;
$vpost = get_post($post->ID);
$filename = $vpost->post_name.".vcf";
//header('Content-type: text/x-vcard; charset=utf-8');
//header("Content-Disposition: attachment; filename=".$filename);
$data=null;
$data.="BEGIN:VCARD\n";
$data.="VERSION:3.0\n";
$data.="FN:".$vpost->post_title."\n"; // get post title
$data.="ORG:" .get_field('nombre_de_la_empresa',$vpost->ID)."\n"; // get acf field value
$data.="EMAIL;TYPE=work:" .get_field('correo_electronico',$vpost->ID)."\n"; // get acf field value
$data.="TEL;WORK;VOICE:" .get_field('telefono_celular',$vpost->ID)."\n"; // get acf field value
$data.="ADR;WORK;PREF:" .get_field('direccion_de_la_empresa',$vpost->ID)."\n"; // get acf field value; // get acf field value
$data.="END:VCARD";
$filePath = "/vcard/".$filename; // you can specify path here where you want to store file.
$file = fopen($filePath,"w");
fwrite($file,$data);
fclose($file);
}
add_action( 'save_post', 'hj_create_vCard' );