REST API: Backbone and custom endpoint

It looks like you are trying to send a POST request to the /istermactive endpoint, is that correct? (I think you may want to remove the trailing slash from the endpoint?) I’m not really sure the wp-api client is the right tool for a standard ajax POST, you may want to use jQuery.ajax or use … Read more

How to return Meta data from the REST API?

The first parameter passed to register_meta() is always post for posts, Pages (post type of page) and custom post types. However, the REST API Handbook says that: Prior WordPress 4.9.8, meta fields set to show_in_rest using register_meta are registered for all objects of a given type. If one custom post type shows a meta field, … Read more

How do I fetch the static front page using the REST API?

We could implement our own endpoint: https://example.tld/wpse/v1/frontpage Here’s a simple demo (PHP 5.4+): <?php /** * Plugin Name: WPSE – Static Frontpage Rest Endpoint */ namespace WPSE\RestAPI\Frontpage; \add_action( ‘rest_api_init’, function() { \register_rest_route( ‘wpse/v1’, ‘/frontpage/’, [ ‘methods’ => ‘GET’, ‘callback’ => __NAMESPACE__.’\rest_results’ ] ); } ); function rest_results( $request ) { // Get the ID of … Read more

How to use _embed when using _fields?

It is not clear in the documentation, but you need to include the “_links” and “_embedded” as fields to be returned. In addition, I include the _embed parameter, as it does not require a value. As of WordPress 5.4, the resources to embed can be limited by passing a list of link relation names to … Read more

Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)

To me, the simplest solution would be creating additional field in JSON response and populating it with selected post meta: function create_api_posts_meta_field() { // “tribe_venue” is your post type name, // “protected-fields” is a name for new JSON field register_rest_field( ‘tribe_venue’, ‘protected-fields’, [ ‘get_callback’ => ‘get_post_meta_for_api’, ‘schema’ => null, ] ); } add_action( ‘rest_api_init’, ‘create_api_posts_meta_field’ … Read more

Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API

I ended up extending the API like suggested in the comments to my question, although I was hoping there was a default route that fetched all posts of all post types. Apparently, there isn’t. So here’s my solution: add_action( ‘rest_api_init’, ‘custom_api_get_all_posts’ ); function custom_api_get_all_posts() { register_rest_route( ‘custom/v1’, ‘/all-posts’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘custom_api_get_all_posts_callback’ … Read more

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