ping_status in JSON REST API

According to WordPress Codex, pings tells Whether the current post is open for pings. In human words, A ping is a “this site has new content” notification that invites search engine bots to visit your blog. For more info, have a look at this blog article.

rest_post_query on multiple post types?

Define the callback as a named function and hook it separately for each post type. function wpse_299908_order_rest_query( $args ) { $args[‘orderby’] = ‘menu_order’; $args[‘order’] = ‘ASC’; return $args; } add_filter( ‘rest_post_query’, ‘wpse_299908_order_rest_query’ ); add_filter( ‘rest_page_query’, ‘wpse_299908_order_rest_query’ ); There’s no filter that automatically applies to all endpoints, likely for the same reason that you can’t query … Read more

WordPress Gutenberg get page template value when post updated?

So I found a solution. There are 4 hooks that can be used to accomplish this depending on the exact needs. The hooks are from wp-includes/meta.php in functions update_metadata() and add_metadata(). Hooks: update_postmeta updated_postmeta add_post_meta added_post_meta These are called at different states and from the names it is pretty self self explanatory. add_post_meta and update_postmeta … Read more

Filter post content in REST API

It looks to me like you’ve written $data->$data[…] where you mean to have $data->data[…]. The “object to string” conversion error is probably due to the second $data, where PHP expects an object’s property name but is getting another reference to the $data object.

Accessing plugin functionality within WP REST API

I have figured out the problem, after trying a load of things I wanted to double check plugins weren’t being loaded at all within the REST API. I added some rudimentary debugging to the plugin in question and I saw that the plugin was indeed being loaded, my issue was that in these conditions the … Read more

Can I define multiple callback methods depending on the call method?

Check if your code looks like this because in the question you pass each method as separate function arguments (I have overlooked it earlier) add_action( ‘rest_api_init’, function () { register_rest_route(‘my-project/v1/’, ‘/form’, array( array(‘methods’ => ‘GET’, ‘callback’ => ‘GET_form’, ), array(‘methods’ => ‘POST’, ‘callback’ => ‘post_form’ ) ) ); }); As you can read in documentation: … Read more

REST-API: extend media-endpoint

I found the solution for my problem. The object type for media is not media, it’s just attachment. So the following code works for me: <?php /** * Plugin Name: REST Response Modifier * Description: A simple plugin to modify the rest api * Author: TheBalco * Author URI: http://somepage.dev */ add_action(‘rest_api_init’, ‘tb_add_custom_rest_fields’); function tb_add_custom_rest_fields() … Read more

Upload image to wordpress using REST API

You can upload images just like your normal PHP/Wordpress file uploads. Reference => wp_handle_upload $mimes = array( ‘bmp’ => ‘image/bmp’, ‘gif’ => ‘image/gif’, ‘jpe’ => ‘image/jpeg’, ‘jpeg’ => ‘image/jpeg’, ‘jpg’ => ‘image/jpeg’, ‘png’ => ‘image/png’, ‘tif’ => ‘image/tiff’, ‘tiff’ => ‘image/tiff’ ); $overrides = array( ‘mimes’ => $mimes, ‘test_form’ => false ); $upload = wp_handle_upload( … Read more

Trying to get an api request getting error 404

Try using a GET request instead of a POST request. The headers indicate they only allow origin from weedmaps.com in the POST request. The method in WordPress is wp_remote_get(). function call_for_api() { $url=”https://api-v2.weedmaps.com/api/v2/listings”; $response = wp_remote_get( $url, array( ‘timeout’ => 45, ‘redirection’ => 5, ‘httpversion’ => ‘1.0’, ‘blocking’ => true, ‘headers’ => array( ‘accept’ => … Read more