创建新帖子后,我需要生成并存储.vcf文件。保存后,我不知道如何做到这一点。没有找到帮助来发展这种功能。请帮忙!
答案 0 :(得分:0)
试试这个:
在“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' );