Why is per_page not working with categories in WP API?

Pretty much all the URLs you are using are invalid in some way: http://foobar.com/wp-json/wp/v2/posts/categories_name=hello categories_name is not a valid argument for listing posts, and even if it was you are missing the ? part of the query string. http://foobar.com/wp-json/wp/v2/posts/categories_name=hello?per_page=‌​1 This one is also missing the ?. Query parameters on a URL, which the API uses … Read more

External WordPress API

As of WordPress 4.7 (released December 2016), a REST API is provided out of the box on WordPress. As you’re probably aware, REST APIs are interfaced with by standard HTTP GET and POST requests, so if you have a WordPress 4.7 installation, you can access it at this URL, by plugging this into your browser: … Read more

Use an attachment in multiple posts

When inside of the media uploaded in the post edit screen, just search for your previously attached media and embed it in your new post. The relationship between posts and attachments is preserved in the database. While an attachment can only belong to one post, it can still be embedded in many posts without worry.

REST API for Multisite

I’m using the REST API to pull data about one multisite installation and feed it to sites in another multisite installation. Here’s some of the code in use: class WPSE205354_Demo { function __construct() { add_filter( ‘json_endpoints’, array( $this, ‘register_routes’ ) ); } /** * Register the additional API routes * @param array $routes The routes … Read more

Send data to 3rd party api with wp_remote_post on wp_login

The ‘body’ needs to be an array, not including the ‘json_encode($user)’ piece. $response = wp_remote_post( ‘myapp.com/endpoint’, array( ‘method’ => ‘POST’, ‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’), ‘body’ => $user ) ); I have this in my function since I also had issues with the body being an object: if (is_object($user) && !is_array($user)) $user = json_decode(json_encode($user), … Read more

Get Latest Plugin Version from WP API

Ok – here is a method – thanks to @Rarst for pointing me in the right direction. Include the require file if the plugins_api function is not found: if ( ! function_exists( ‘plugins_api’ ) ) { require_once( ABSPATH . ‘wp-admin/includes/plugin-install.php’ ); } Then, prepare a query to pass to plugins_api(): // set the arguments to … Read more

WP.org API: Accessing plugin downloads “Today” value?

Late answer A mini plugin as local API This plugin gives you – after you filled in the slug of your repository – the downloads stats as array. The keys are the dates, the values the downloads. <?php /** Plugin Name: (#84254) Plugin stats API */ function wpse84254_get_download_stats() { $response = wp_remote_request( add_query_arg( ‘slug’ ,’YOUR-REPO-PLUGIN-SLUG’ … Read more

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