WP JSON REST API (Ryan McCue) how to query posts with specific meta data with ‘AND’ relation?

Sorry for answering my own question but it may help some other devs too. I created this additional filter ‘json_query_var-meta_query’that returns the necessary arguments. function adjustQrry($data){ $args = array(); $args[‘relation’] = ‘AND’; foreach ($data as $key=>$value) { if ( ‘relation’ === $key ) { $args[‘relation’] = $data[‘relation’]; } if ( substr($key, 0, 3) === ‘key’ … Read more

Using Backbone with the WordPress AJAX API

You need to override the Backbone.sync function to change the URL used for the AJAX call. You can learn from the plugin wp-backbone does this and more. Below you can see from it how it changes all the actions into either POST or GET, create the parameters, add the action parameter and more. (function($) { … Read more

Getting user meta data from WP REST API

Look into register_rest_field() to register meta with the rest api. add_action( ‘rest_api_init’, ‘adding_user_meta_rest’ ); function adding_user_meta_rest() { register_rest_field( ‘user’, ‘collapsed_widgets’, array( ‘get_callback’ => ‘user_meta_callback’, ‘update_callback’ => null, ‘schema’ => null, ) ); } And then put your get_user_meta bit in the callback. function user_meta_callback( $user, $field_name, $request) { return get_user_meta( $user[ ‘id’ ], $field_name, true … Read more

Displaying a page built with Elementor using the REST API [closed]

you can create a new endpoint with the following code and you can retrieve the elementor content on URL wp-json/MyPlugin/v1/pages/PAGE_ID/contentElementor add_action(“rest_api_init”, function () { register_rest_route( “MyPlugin/v1” , “/pages/(?P<id>\d+)/contentElementor” , [ “methods” => “GET”, “callback” => function (\WP_REST_Request $req) { $contentElementor = “”; if (class_exists(“\\Elementor\\Plugin”)) { $post_ID = $req->get_param(“id”); $pluginElementor = \Elementor\Plugin::instance(); $contentElementor = $pluginElementor->frontend->get_builder_content($post_ID); } … Read more

WP REST API Require Password for GET Endpoint

When we register a rest route with register_rest_route(), then we can use the permission_callback parameter with the kind of permission we want. Check for example how WP_REST_Posts_Controller::register_routes() and WP_REST_Users_Controller::register_routes() implement the permission callback. The password argument you’re referring to is the content’s password, that you can set for each post and that’s not the same. … Read more

How would I add custom tables/endpoints to the WP REST API?

I eventualy worked out a solution for my restaurants table, which sits alongside the wp_* tables in my WP database. Hope this helps add_action( ‘rest_api_init’, function () { register_rest_route( ‘restos/v1’, ‘/all’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘handle_get_all’, ‘permission_callback’ => function () { return current_user_can( ‘edit_others_posts’ ); } ) ); } ); function handle_get_all( $data … Read more

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