WP Rest API v2 filter and display latest post with specific tag

I need to display the latest post with a specific tag. Example: User tags a post ‘featured’, but forgets to untag earlier posts. So I want to ensure that the latest post tagged ‘featured’ is what displays on other sites. https://my-site.com/wp-json/wp/v2/tags/&filterbylatestdatesomehow 1 1 You can actually find extensive documentation on wordpress.org. But let’s have a … Read more

WP API returning SQL results as strings, rather than numbers

I have this code, but what I get in the browser are all the fields – even those stored as Int and Bool in SQL – as strings. add_action( ‘rest_api_init’, function () { register_rest_route( ‘restos/v1’, ‘/resto/(?P<qname>.*)’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘handle_get’, ‘permission_callback’ => function () { return current_user_can( ‘edit_others_posts’ ); } ) ); … Read more

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

WordPress has several APIs build in: XML-RPC REST API by default they don’t return custom post types or protected meta keys. I want to access the protected meta fields of a plugin. I tried to follow the examples given here and here. I did manage that the wp-json API would return custom post types by … Read more

How do I cache (core) API requests?

I’m am currently trialling the new (as of 2017) core API built into WordPress. My setup is reasonably simple: +———+ +——+ +———+ |Wordpress|<–>|Guzzle|<–>| App | |(API) | +——+ |(PHPSlim)| +———+ +———+ Guzzle will be operating through a local loopback (/etc/hosts set up to see the api as a local resource). The major players in the … Read more

WP-API v2 Custom Endpoint Response Formatting

I’m trying to use a custom endpoint (basically to get a random sorting working) and am using the following code: // Custom WP API endpoint function theme_enable_random_api() { // create json-api endpoint add_action(‘rest_api_init’, function () { // http://example.com/wp-json/random/v2/posts register_rest_route(‘random/v2’, ‘/random’, array ( ‘methods’ => ‘GET’, ‘callback’ => ‘wp_json_offers_v2__posts’, ‘permission_callback’ => function (WP_REST_Request $request) { return … Read more

Show popular post in another php website via WP REST JSON API

I need to show popular & recent posts in another PHP web site under the same domain. Example: www.example.com -> main website (php, mysql) www.example.com/blog -> WordPress blog Need to show popular, recent posts of blog in the main website. Please note that blog and main website use two separate database. I decided to use … Read more