Skip Navigation

[Resolved] Custom View to output xml / json / serialize data instead of HTML

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 10 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by jose-alfonsod 10 years, 3 months ago.

Assisted by: Caridad.

Author
Posts
#130953

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

#131374

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

#131402

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?

#131437

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

#133160

Thank You very much!

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.