Hi, as long as WordPress has no build in REST-API you must enable the WordPress REST-API by the plugin https://ww.wp.xz.cn/plugins/rest-api/.
After installing the plugin, you can get for example data of the page with post_id 2 like this:
yoursite.com/wp-json/wp/v2/pages/2/
But the result does not include the meta/acf data of the page. To get the acf fields of a page, you have to register the fields in the API. Put the following code in your themes functions.php file
function api_page_get_acf_fields( $object, $field_name, $request ) {
return get_fields( $object[ 'id' ] );
}
add_action( 'rest_api_init', function() {
register_api_field( 'page', // the post-type
'acf-fields', // the key in the JSON result
array(
'get_callback' => 'api_page_get_acf_fields',
)
);
});
Now you can get the data of a page including the ACF fields via the REST-API. But notice, the WordPress REST-API is still in development.
To encode ACF table data as JSON you can do following:
$table_data_array = get_field( 'your_table_field_name' );
$table_data_json = json_encode( $table_data_array );
Hello,
My array after json_decode:
Array (
[p] => Array ( [o] => Array ( [uh] => 0 ) )
[c] => Array ( [0] => Array ( [p] => ) )
[h] => Array ( [0] => Array ( [c] => domain ) )
[b] => Array ( [0] => Array ( [0] => Array ( [c] => domain ) ) )
)
How i can echo”domain” from array for because i don’t now about Array table
Thanks for support
echo $table['b'][0][0]['c'];
This code echo the first top, left table cell of the tables body. [‘b’] represents “body”. The first [‘0’] represents the first row. The second [‘0’] represents the first cell of the row. [‘c’] represents the content of a cell. And so on. [h] represents the table header. Because there is only one row as the header you can echo the first cell by:
echo $table['h'][0]['c'];