从 WordPress Post 数据生成联系人文件 (.vcf)?

Generate Contact File (.vcf) from WordPress Post Data?

创建新的 post 后,我需要生成 .vcf 文件并将其存储在存储器中。我不知道 post 保存后我该如何做。没有找到开发此类功能的帮助。请帮忙!

试试这个:

在 "save_post" 钩子上你可以写函数。这将在指定目录创建名称为 post_title 的 .vcf 文件。

function my_project_create_vCard( $post_id ) {
    $vpost = get_post($post->ID);
    $filename = strtolower(str_replace(" ","-",$vpost->post_title)).".vcf";
    header('Content-type: text/x-vcard; charset=utf-8');
    header("Content-Disposition: attachment; filename=".$filename);
    $data=null;
    $data.="BEGIN:VCARD\n";
    $data.="VERSION:2.1\n";
    $data.="FN:".$vpost->post_title."\n"; // get post title
    $data.="EMAIL:" .get_field('email',$vpost->ID)."\n";  // get acf field value
    $data.="END:VCARD";
    $filePath = get_template_directory()."/".$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', 'my_project_create_vCard' );