REST API parameters not working with nginx

If your virtual host looks like this: try_files $uri $uri/ /index.php$args; change it to this: try_files $uri $uri/ /index.php$is_args$args; Adding $is_args (which will print a ? character if query arguments are found) will allow WordPress to properly receive and interpret the query parameters

node-wpapi: how to handle authentication?

I’m the author of the node-wpapi library, thanks for checking it out. Unfortunately we do not currently support any external authentication scheme out of the box, because WordPress itself does not ship with any authentication scheme other than the cookie/nonce option (which doesn’t work with external apps, as you describe). There are plugins for authenticating … Read more

Inserting custom post meta value using WP-REST API

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

Obtain full v2 REST url?

You could add the path argument to the get_rest_url() function as per the WordPress Developer docs – https://developer.wordpress.org/reference/functions/get_rest_url/ – in order to get the path you need: get_rest_url( null, ‘wp/v2/’ ); This would produce: http://mywebsite.com/wp-json/wp/v2/

Check Password Strength using WordPress API

WordPress uses the zxcvbn javascript library by Dropbox, to estimate the password strength. We can see the implementation in: /wp-admin/js/password-strength-meter.js /wp-admin/js/user-profile.js with: strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); As far as I know there’s no explicit PHP WordPress API for estimating the password strength, but zxcvbn has been ported to a PHP library here, … Read more

How to search by metadata using REST API

How can I search it by metadata? As far as I know, there’s no standard/built-in way of doing that (for the time being). But with custom coding, you can make it possible: You can append a city to the query string: /wp-json/wp/v2/horario_busao?city=London And then use the rest_{$this->post_type}_query filter to set the meta key/value pair which … Read more

Gutenberg Custom Block Getting All Posts

In addition to loading the wp-api script as mentioned here: wp_enqueue_script( ‘wp-api’ ); // or use below when enqueueing as dependency //wp_enqueue_script( ‘my_script’, ‘path/to/my/script’, array( ‘wp-api’ ) ); You should also know that each collection is a function (equivalent to a class in PHP), so you need to use the new keyword to instantiate a … Read more

How to retrieve custom meta term of category taxonomy from WP Rest API?

First you need to tell WordPress to show this custom field in the API response: register_term_meta(‘category’, ‘_category_color’, [‘show_in_rest’ => true]); Then you can filter the category term API endpoint like so: add_filter( ‘rest_prepare_category’,function($response, $item, $request){ $color = get_term_meta( $item->term_id, ‘_category_color’, true ); $response->data[‘color’] = $color ?: ”; return $response; }, 10, 3);

Application Password is not enable by default?

If you want to add that single filter, you can do it in your theme’s functions.php file. If you’d prefer to keep it out of the theme, you can make it a simple Must Use Plugin. Make a file like wp-content/mu-plugins/enable-application-passwords.php with this file content: <?php /** * Plugin Name: Enable Application Passwords * Description: … Read more

WordPress Rest API response

You might be able to output your headers with the response. Then just kill the request with exit();. The default is usually to return a value and let the process encode and output for you. Based on http://v2.wp-api.org/extending/adding/ function my_awesome_func( $data ) { header(“Content-Type: text/plain”); print_r( array(‘foo’=>’bar’)); exit(); } add_action( ‘rest_api_init’, function () { register_rest_route( … Read more