WordPress Unexpected token < in JSON at position 0
WordPress Unexpected token < in JSON at position 0
WordPress Unexpected token < in JSON at position 0
I can’t’ seem to figure it out, shouldn’t using json_encode allow me to treat the response as a json object? It does allow you to treat it as a JSON object, but that’s useless in PHP. You want the result to be turned from JSON into a PHP array. The required steps are: Make the … Read more
Generate/save JSON or XML file from JSON script
You should use content_save_pre filter. And maybe try some “simple” content first. wp_insert_post_data is fired in a lot of situations 🙂 Even at deleting.
get_category_posts/?slug=cat1&post_type=project I forgot to set post_type.
I’m not sure whether you are using a plugin, or you are coding it yourself. Either way, you can use server side or client side to decode or encode your content. PHP offers the utf8_decode(); and utf8_encode(); functions, that can be used to decode or encode your content before sending it to the browser, or … Read more
Normally, when one want to put strings to be used in javascript, esc_js is the right function, not esc_attr. The problem is that esc_js, according to docs: Escapes text strings for echoing in JS (bold mine). So, using with esc_js you obtain a string that can be safely echoed in js, not parsed: it’s not … Read more
Since you’re filtering with the rest_prepare_{post_type} filter, you could restrict it to the WP_REST_Posts_Controller::get_items() callback, with the rest_{post_type}_query filter: add_filter( ‘rest_post_query’, function( $args ) { add_filter( ‘rest_prepare_post’, ‘api_remove_extra_data’, 12, 3 ); return $args; } ); where the post type is post. Note that in general we always want to return the filter value and I … Read more
If you’re creating the theme yourself, you can always use Schema Microata markup directly in the theme itself. As we can see in the below example, adding extra attributes to your HTML can make it Schema compliant. In this instance, we are using itemscope, itemtype and itemprop: Taken from http://schema.org/docs/gs.html#microdata_how <div itemscope itemtype =”http://schema.org/Movie”> <h1 … Read more
Well, there is a way to update post meta. You have to add the update_callback when registering rest field. See the example below: function rest_api_player_meta() { register_rest_field(‘sp_player’, ‘player_meta’, array( ‘get_callback’ => ‘get_player_meta’, ‘update_callback’ => ‘update_player_meta’, ‘schema’ => null, ) ); } function get_player_meta($object) { $postId = $object[‘id’]; return get_post_meta($postId); } function update_player_meta($meta, $post) { $postId … Read more