Download the PHP package aucor/wp_query-route-to-rest-api without Composer

On this page you can find all versions of the php package aucor/wp_query-route-to-rest-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp_query-route-to-rest-api

WP_Query Route To REST API

Contributors: Teemu Suoranta, Sami Keijonen, Christian Nikkanen

Tags: WordPress, REST API, WP_Query

License: GPLv2+

Description

Adds new route /wp-json/wp_query/args/ to REST API. You can query content with WP_Query args. There's extensive filters and actions to limit or extend functionality.

How to use

Basic usage

Route: /wp-json/wp_query/args/

Get three projects: /wp-json/wp_query/args/?post_type=project&posts_per_page=3

You shoudn't write query args by hand! It gets very complicated when you want to pass arrays for example with meta_query.

Use with PHP

1. Create $args

2. Turn $args into query string (Reference)

3. Make the call

Use with JS

1. Create args

2 a) Create params with for example using @wordpress/url package

2 b) Some other JS solution query-string handles most use cases, but as query strings aren't really standardized, YMMV.

One example of where it falls short:

One possible solution, ES2015:

2 c) Create params with jQuery

3. Make the call

Or with jQuery.

Advanced examples

Advanced example: tax_query

Get posts that have both tags "wordpress" and "woocommerce"

PHP:

JS:

Advanced example: tax_query with relation

Get posts that have either "wordpress" or "woocommerce" tag. This gets tricky because JS doesn't support completely the same array structure as PHP. If you only need PHP, this is a piece of cake.

PHP:

JS:

For other uses, keep in mind JS object/array syntax. If there's key + value, use object {}. If theres only value, use array [].

Advanced example: modifying existing WP_Query (post archive, term archive, search etc)

Sometimes you need to create features that add small tweaks to current query that WordPress, theme or plugins has already defined. These include "load more" buttons, filters etc. You can create that query from scratch if you want, but there is a neat way to get the current query for JS.

You can add this to your archive.php or whatever PHP template you need:

Now you can access the query in JS from this var wp_query. Props @timiwahalahti for this idea.

Restrictions

The route /wp-json/wp_query/args/ sets some restrictions by default for queries. These restrictions can be lifted or hardened with filters and actions.

Allowed args

So biggest ones missing have something to do with getting content that you might not want to get like post_status drafts (add this argument to the list with filter if you need it). By default, no querying post_passwords or having your way with cache settings.

Post types

By default all the post types marked 'show_in_rest' => true are available. 'post_type' => 'any' falls back to these post types. You can change post types with filter to what you want.

Post status

By default, only "publish" is allowed. Add other post_status as needed with filter.

Restriction fail-safe

Addition to restriction of WP_Query args, there is check after the query that queried posts will not be forbidden post types or post_status.

Default WP_Query

In addition to the normal defaults from WP_Query.

Extra plugin compatibility features

This plugin has built-in compatibility for Relevanssi ('s' argument) and Polylang ('lang' argument)

Filters

Add more allowed args:

Add more default args:

Add allowed post types:

You can also add post types by setting 'show_in_rest' => true when registering post type.

Add allowed post status:

Is current post allowed:

Alter any argument value:

Check permissions:

Limit max posts per page:

Modify default $data:

Modify $data after loop:

Remove post type meta:

Remove parent class:

Hooks

Before WP_Query:

After WP_Query:

Install

Download and activate. That's it.

Composer:

With composer.json:

Issues and feature whishlist

This is a WordPress plugin by 3rd party developer. WordPress.org or Automattic has nothing to do with this plugin. There's no warranty or quarantees. Thread carefully.

If you see a critical functionality missing, please contribute!

Looking for similar API to WP_User_Query?

Install also MEOM/meom-user-query

Changelog

1.3.2

Fix PHP warning caused by 1.3.0 argument sanitizing refactoring.

1.3.1

Fix composer license to a valid license.

1.3.0

Compatibility release with a few new features. 100% backwards compatible.

1.2.0

WordPress.org release.

1.1.1

Added advanced example in readme for getting PHP WP_Query for JS. Added table of contents. Made the title hierarchy more logical.

1.1

Make the return data structure same as /wp-json/wp/posts/. The data schema was missing some data before. Now the structure is inherited from the WP_REST_Posts_Controller as it should have from the start.


All versions of wp_query-route-to-rest-api with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aucor/wp_query-route-to-rest-api contains the following files

Loading the files please wait ....