chris_mcclellan
Forum Replies Created
-
Forum: Plugins
In reply to: [JSON API] Get JSON from within themeForum: Plugins
In reply to: [JSON API] Can I spit out the same JSON without a Web query?Forum: Plugins
In reply to: [JSON API] Can I spit out the same JSON without a Web query?These lead me to believe it may be more difficult that one would hope.
add_action('template_redirect', array(&$this, 'template_redirect')); add_action('admin_menu', array(&$this, 'admin_menu')); add_action('update_option_json_api_base', array(&$this, 'flush_rewrite_rules')); add_action('pre_update_option_json_api_controllers', array(&$this, 'update_controllers'));
Forum: Plugins
In reply to: [JSON API] Can I spit out the same JSON without a Web query?Any luck? I would love to bootstrap my wordpress theme without doing a separate request after the dom is ready.
Forum: Plugins
In reply to: [JSON API] FIXED: Get all custom fields the right way!FIXED. Now this returns the array correctly… ugh that should have been the solution from the beginning.
ENJOY!
// Updated <code>set_custom_fields_value()</code> to retreive all fields properly function set_custom_fields_value() { global $json_api; // Query string params for this query var $params = trim($json_api->query->custom_fields); $wp_custom_fields = get_post_custom($this->id); $this->custom_fields = new stdClass(); // Loop through our custom fields and place on property foreach($wp_custom_fields as $key => $val) { if ( $val ) { // Some fields are stored as serialized arrays. // This method is not recursive. Does not support multidimensional arrays. $current_custom_field = @unserialize($val[0]); if (is_array($current_custom_field)) { // This item is an array - lets append it as such $this->custom_fields->$key = $current_custom_field; } else { // Break this value of this custom field out of its array // and place it on the json blob like usual $this->custom_fields->$key = $val[0]; } } } }
Forum: Plugins
In reply to: [JSON API] FIXED: Get all custom fields the right way!hmmm. I’ll give it a look when I get home.
It should work as there are only minor changes on the original code base.Forum: Plugins
In reply to: [JSON API] FIXED: Get all custom fields the right way!You could try… Sorry i’m at work so I can’t test it.
$this->custom_fields->$key[$sub_key] = $sub_val;
Forum: Plugins
In reply to: [JSON API] FIXED: Get all custom fields the right way!I’m using this one now which just adds the custom fields every time – this way its less string manipulation I have to perform at any given point. This works for me… and does not address that line you posted.
// Updated <code>set_custom_fields_value()</code> to retreive all fields properly function set_custom_fields_value() { global $json_api; // Query string params for this query var $params = trim($json_api->query->custom_fields); $wp_custom_fields = get_post_custom($this->id); $this->custom_fields = new stdClass(); // Loop through our custom fields and place on property foreach($wp_custom_fields as $key => $val) { if ( $val ) { // Some fields are stored as serialized arrays. // This method is not recursive. Does not support multidimensional arrays. $current_custom_field = @unserialize($val[0]); if (is_array($current_custom_field)) { // Loop through the unserialized array foreach($current_custom_field as $sub_key => $sub_val) { // Lets append these for correct JSON output $this->custom_fields->$key->$sub_key = $sub_val; } } else { // Break this value of this custom field out of its array // and place it on the json blob like usual $this->custom_fields->$key = $val[0]; } } } }
Forum: Plugins
In reply to: [JSON API] FIXED: Get all custom fields the right way!There really isn’t anything different about the way you get custom_fields from the way it was done originally. You can just retrieve all of your custom fields at one time without having to pass which custom fields you want like the old way.
OLD WAY:
https://myurl.com/?json=true&custom_fields=_my_var_1,_my_var_2,_my_var_2Forum: Plugins
In reply to: [JSON API] FIXED: Get all custom fields the right way!This only checks for a serialized array in your custom field but doesn’t affect anything if it doesn’t exist.
You should just overwrite the set_custom_fields_value(){ … }
with the one above and you should be able to pass custom_fields=all to get all your custom fieldsForum: Plugins
In reply to: [JSON API] FIXED: Get all custom fields the right way!This is in /models/post.php