WP Rest endpoint with custom post type and ACF Fields

Advanced custom fields uses get_field() function to retrieve the fields. So, all you have to do is to retrieve them by using: $field = get_field(‘field_name’, $post->ID, ‘format_value’); for each of your fields in the loop. You can read this page for more information. Questions about plugins are off-topic here, That’s why your question haven’t receive … Read more

Adding rest api endpoints to an old theme

WordPress REST API has nothing directly to do with the theme, REST API is in the WordPress core, and any plugin and theme can be made to support it. Normal WordPress themes don’t use REST API: it is relatively new part of the WordPress, and so far, very few themes are made to use REST … Read more

wp-json and what data does it give away?

/wp-json/ is the base part of the WordPress REST API https://developer.wordpress.org/rest-api/ An authors ID isn’t a big deal. I would imagine on your theme, every time the post authors name shows, within the HTML showing the name, there’d be element classes containing the authors ID. It’s normal to have shown in publicly viewable source code, … Read more

Rest API Multisite Site List?

There is no built-in endpoint for sites on a multisite network. As can be seen in the documentation, the built-in endpoints are: +—————-+——————-+ | Posts | /wp/v2/posts | +—————-+——————-+ | Post Revisions | /wp/v2/revisions | +—————-+——————-+ | Categories | /wp/v2/categories | +—————-+——————-+ | Tags | /wp/v2/tags | +—————-+——————-+ | Pages | /wp/v2/pages | +—————-+——————-+ | … Read more

WP REST API Post Status Using JavaScript

In this tutorial, the post var status=”draft”; (see code). So I am just worried that won’t anyone able to hack that status? It depends who it is. A logged out user cannot create any posts at all. A subscriber cannot either. A contributor could create the post, but not publish it. An author or editor … Read more

How to use current_user_can() in register_rest_route()?

You need to pass the wp_rest nonce with the JavaScript request that you send to REST. This nonce is what passes the information from PHP to JavaScript about which user is making the request. Example: <form> <input type=”text” name=”rest_auth_nonce” value=”<?= esc_attr( wp_create_nonce( ‘wp_rest’ ) ) ?>”> </form> <script> jQuery.ajax({ beforeSend: function (xhr) { xhr.setRequestHeader(‘X-WP-Nonce’, jQuery(‘form’).find(‘input[name=”rest_auth_nonce”]’).val()); … Read more