I created a custom types fields that is needed for an app. And this field will server as an API of an app. What I need is that I can output a raw xml /json / serialize data based from the customs fields I have on wp-types.
What should my approach here? If I am to create a php file which directory shall I save it?
Thanks in advance
Dear Jose Alfonso,
For example, you can create a separate php file with this code in it:
<?php
//bootstrap WP
require_once "wp-config.php";
//see that we have a post id
$id = intval($_GET['id']);
if (empty($id)) die("Please provide a post id");
//get all custom fields for the post
$data = get_post_custom($id);
//send back as json data
wp_send_json($data);
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad
Hi CaridadZ,
Thanks for your quick reply... May I know which directory shall I save this PHP file? and How do I render it on the browser?
Dear Jose Alfonso,
As it is, you can put it in the root folder of WordPress. If you want to include it in a plugin or a theme its ok, but you need to adjust the path to wp-config.php
require_once "../../../wp-config.php";
Here you have an example of how the function is called from javascript:
http://codex.wordpress.org/Function_Reference/wp_send_json
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad