Skip Navigation

[Closed] output (wpcf) custom field with json api

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 8 years, 11 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.

This topic contains 15 replies, has 2 voices.

Last updated by pierre.s 8 years, 11 months ago.

Assisted by: pierre.s.

Author
Posts
#304868
json_api.jpg

I am trying to:
output custom field (wpcf) with json

I visited this URL:

I expected to see: output Valueof filed

Instead, I got: none ,empty filed

#304883

pierre.s
Supporter

Hello,

Thank you for your message!

If I understand correctly, you have an array stored in a custom field and you want to convert it in a JSON format, that's right?

You can try this:

<?php
$field_in_json_format = json_encode( types_render_field( 'my-custom-field', array( 'output' => 'raw' ) ) );
?>

Check the documentation for json_encode() function: hidden link

Let me know if this helps.

Regards,
Pierre

#304894

I do not understand how to use it....

i have a custom post type template with a custom field....
<span class="citizen"><?php echo types_render_field("citizen", array(""));?></span>
And I want to output this file in json ( i mark "herer" where i want to disply this filed:

---------------------------------------------------------------------------
function showPost(id) {
$.getJSON('hidden link' + id + '&callback=?', function(data) {
var output = '<h3>' + data.post.title + '</h3>';
output += data.post.content;
$('#mypost').html(output);
});

$.getJSON('hidden link' + id + '&callback=?', function(data) {
var output = '<h3>' + data.post.title + '</h3>';
output += data.post.content;
output += $field_in_json_format; <<<<<<<---------- here?????
$('#mypost').html(output);
});
}

#304923

pierre.s
Supporter

As far as I can see, you are making an Ajax request to get a post (javascript executed in the brower).

I don't know the exact structure of your code but I assume the function returning the post data should include the custom field data like this:

// JavaScript
// ...
output += data.post.my_custom_field;
// ...

To add this custom field to the "data" object, it depends on the code structure, but it should be something like this:

<?php
// ... Create data object
// ... Add the post object to the data object
// Add the custom field to the post object
$data->post->my_custom_field = types_render_field( 'my-custom-field', array( 'output' => 'raw' ) );
echo json_encode( $data );
die();

Could share an extract of your server-side code to return the data from the Ajax call?

Regards,
Pierre

#304929

its output "undefined"....

#304937

pierre.s
Supporter

Can you share an extract of the code called by "hidden link' + id + '&callback=?" ?

Regards,
Pierre

#304977

How do I write to you privately?

#304984

pierre.s
Supporter

Your next reply will be private.

Regards,
Pierre

#305010

You get my private
message?

#305156

pierre.s
Supporter

Hello,

I managed to see your private reply but this doesn't help.

To help you on your project, I need to have a look at the PHP code handling the ajax request.
Are you using a plugin to handle this ajax request? Can you share the PHP file?

Regards,
Pierre

#305195

i can send this Details privately?

#305200

pierre.s
Supporter

Your next reply will be private.

Regards,
Pierre

#305459

?

#305524

pierre.s
Supporter

Hello,

I had a look at the plugin JSON API, and as far as I can see in the documentation https://wordpress.org/plugins/json-api/other_notes/#3.2.-Content-modifying-arguments, you have to specify which custom field you need in the arguments of your request.

Your request URL should be like this:

<em><u>hidden link</u></em>?

Does it makes sense to you?

Regards,
Pierre

#305592

I still need help...It does not work

The topic ‘[Closed] output (wpcf) custom field with json api’ is closed to new replies.