Created
June 12, 2013 11:27
-
-
Save bonny/5764511 to your computer and use it in GitHub Desktop.
Example how to use Simple Fields together with WP API. Just a quick example, modify to suit your own needs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function simple_fields_wp_api_json_prepare_post( $_post, $post, $fields ) { | |
// we dont't get the post id | |
$post_id = $_post["ID"]; | |
$field_values = simple_fields_get_all_fields_and_values_for_post($post_id); | |
$field_values_for_json = array( | |
"field_groups" => array() | |
); | |
foreach ( $field_values["field_groups"] as $one_field_group ) { | |
$field_values_for_json["field_groups"][ $one_field_group["slug"] ] = array( | |
"fields" => array() | |
); | |
foreach ( $one_field_group["fields"] as $one_field ) { | |
$field_values_for_json["field_groups"][ $one_field_group["slug"] ]["fields"][ $one_field["slug"] ] = $one_field["saved_values"]; | |
} | |
} | |
$_post["simple_fields"] = $field_values_for_json; | |
return $_post; | |
} | |
// return apply_filters( 'json_prepare_post', $_post, $post, $fields ); | |
add_filter( 'json_prepare_post', "simple_fields_wp_api_json_prepare_post" ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment