npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wpqueryjs

v1.1.1

Published

An axios wrapper for the WordPress REST API.

Downloads

5

Readme

WPQuery.js

An axios wrapper for the WordPress REST API.

Status

npm version JS gzip size downloads Dependencies Status devDependency Status

Getting Started

Methods

request(method, resource, params, config)

A method that returns a Promise with the data that you have queried for. All you have to do is pass the HTTP request you want to perform, along with a resource e.g. Tags, Posts or a Custom Post Type and the parameters you wish to include in your query.

If you want to include any global parameters in your request, you don't need to include the _ character as this will be done for you. Also, when requesting a single listing of a resource you can do this by adding a id property to the params object like the examples below.

Any camel case properties e.g. perPage passed in the params object will change to lowercase and an _ will be added where appropriate. e.g. perPage will change to per_page in your query.

Retrieves a page.

const query = new WPQuery('https://demo.wp-api.org')
    .request('get', 'pages', {
        id: 2,
    });

Retrieves the latest 3 posts published in multiple tags.

const query = new WPQuery('https://demo.wp-api.org')
    .request('get', 'posts', {
        perPage: 3,
        tags: [6, 4],
    });

Retrieves 2 users in descending order by their IDs.

const query = new WPQuery('https://demo.wp-api.org')
    .request('get', 'users', {
        order: 'desc',
        orderby: 'id',
        perPage: 2,
    });

Check the WordPress REST API Handbook for all available resources and parameters.

get(resource, params, config)

A helper for the request method which can be used like the examples below:

Retrieves posts.

const query = new WPQuery('https://demo.wp-api.org').get();

Retrieves posts published by a specific author.

const query = new WPQuery('https://demo.wp-api.org')
    .get('posts', {
        author: 103,
    });

Retrieves posts published in a specific category.

const query = new WPQuery('https://demo.wp-api.org')
    .get('posts', {
        category: 11,
    });

Check the WordPress REST API Handbook for all available resources and parameters.

post(resource, params, config)

Note: Authorization will be required for all POST requests to your WordPress site, see Authorization for more information.

A helper method for the request method which can be used like the examples below if you are authorizing your requests with a nonce:

Creates a new post.

const query = new WPQuery('https://demo.wp-api.org')
    .post('posts', {
        title: 'The title of my new post',
        content: 'The content of my new post.',
    }, {
        headers: {
            'X-WP-NONCE': '',
        }
    });

Creates a new category.

const query = new WPQuery('https://demo.wp-api.org')
    .post('categories', {
        name: 'Music'
    }, {
        headers: {
            'X-WP-NONCE': '',
        }
    });

Creates a new user.

const query = new WPQuery('https://demo.wp-api.org')
    .post('users', {
        username: 'johnsmith',
        email: '[email protected]',
        password: '4QKu$jq6?+Gu,uVs,9oG',
    }, {
        headers: {
            'X-WP-NONCE': '',
        }
    });

Check the WordPress REST API Handbook for all available resources and parameters.

Compatibility

WPQuery.js supports the latest, stable releases of all major browsers except Internet Explorer.

We use JavaScript promises as they offer superior advantages than event listeners. You can find browser compatibility statistics for Promises on Can I use....

However, for a quick overview - read the table below which shows you the browser support for WPQuery.js. All browser tests are conducted with Browser Stack.

| Microsoft Edge | Mozilla Firefox | Google Chrome | Safari | Opera | | --------- | --------- | --------- | --------- | --------- | | >=12 | >=30 | >=32 | >=7.1 | >=20 |

Contributing

Feel free to submit a pull request with any changes that will help make this project better!