Generate vcard from custom meta fields? - Wordpress Solution
[Solved] - Generate vcard from custom meta fields? - Wordpress Solution |
---|
Try following codes |
I am using a custom post type to enter employees for a company, and want people to be able to download vcards for each employee, generated from the custom meta fields for each employee, but I'm really stuck here, how would I do this?
The code for the custom post type is
and the meta fields
Solution - 1Basically, you need to use set the content type of the http return and then write out what ever content you want. Probably the best way is the extent the template that you're using to display each employee. I guess for that you've got a single-ansatte.php file? If so, then make your link for the vcard something like http://www.your-site.com/ansatte/employee-name?vcard=1 (ie whatever the current url is with ?vcard=1 on the end). Then BEFORE your get_header() call put something along the following lines: Clearly, you have more to show so you'd need to check out the complete spec to write each of the lines you want. UPDATE: Added a new line after each echo as pointed out by Torstein (just in case anyone is copying this code). Solution - 2I think this could be realized best as a custom plug-in. The way I see it, the plugin-should add a new page or URL to the site, say something like /get_vcard. This page should then be called with the ID of the employee you want to generate a vCard for, like /get_vcard?employee=123. The plugin would then generate the vCard file using the custom metadata associated with the employee in question, set the content-type header to the right value and echo the vCard to the browser. I think I should be able to come up with a reasonable solution to do this which works in the way described above. Please let me know if you want me to go ahead and write some code. |
Date: 2022-10-21 05:12:51 |
Category: Wordpress |