How to add WP API and JS featured image attachment

I manage to solved it by adding this code (at the bottom) to the YOUR BLOG THEMES my path : wp-content/themes/twentysixteen/function.php: function ws_register_images_field() { register_rest_field( ‘post’, ‘images’, array( ‘get_callback’ => ‘ws_get_images_urls’, ‘update_callback’ => null, ‘schema’ => null, ) ); } add_action( ‘rest_api_init’, ‘ws_register_images_field’ ); function ws_get_images_urls( $object, $field_name, $request ) { $medium = wp_get_attachment_image_src( get_post_thumbnail_id( … Read more

WP REST API – Limit the taxonomy search to the first letter

You can use the rest_names_query filter to handle the custom starts_with REST API parameter, and use the terms_clauses filter to add a custom SQL clause for searching terms having their name starting with the specified letter (e.g. A or a for /wp/v2/names/?starts_with=A): add_filter( ‘rest_names_query’, function( $args, $request ){ if ( ‘/wp/v2/names’ === $request->get_route() && // … Read more

Passing a borrowed nonce through Postman fails

For remote apps (cURL, Postman, etc.), or when not using the browser, you should use an authentication plugin like Application Passwords instead of sending the cookies. But if you’d rather send the cookies, then copy and send the WordPress logged-in cookie named wordpress_logged_in_<hash>. Example in cURL: curl -H “X-WP-Nonce: <nonce>” -X POST https://example.com/wp-json/wp/v2/posts -d “Data … Read more

WP 5.5 Fatal Error – get_rest_controller() in rest-api.php

Since 5.5 WP_Taxonomy objects now have a new method, get_rest_controller(), to allow for per-taxonomy controller overrides. The problem is that your plugin overwrites the taxonomy saved in the global $wp_taxonomies cache with a version that isn’t a real WP_Taxonomy object, just a stdObject property bag, and so does not have get_rest_controller() to call. This is … Read more

Using pre_get_posts, how to target the REST API, only?

Yes. So long as the code you’re running happens after parse_request – which pre_get_posts does. (See https://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request) Then you will have a nice constant to use: REST_REQUEST Something like if( defined( ‘REST_REQUEST’ ) && REST_REQUEST ) { // …do RESTy things } will do the trick. See /wp-includes/rest-api.php

Exclude posts w/ specific post_meta on Rest API endpoint

Caveat From the REST API docs: Changing or removing data from core REST API endpoint responses can break plugins or WordPress core behavior, and should be avoided wherever possible. That said, there’s a rest_post_query filter (well, rest_{$this->post_type}_query) that will let you modify the WP_Query that’s grabbing your posts, so you should be able to add … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)