WP REST Filter

Description

Since WordPress 4.7 the filter argument for any post endpoint was removed.

This plugin restores the filter parameter for websites that were previously using it.

Usage

Use the filter parameter on any Post, or Custom Post Type endpoint such as /wp/v2/posts or /wp/v2/cpt as an array of WP_Query
argument. ACF values are also supported.

Default Post:
fetch( 'https://domain.com/wp-json/wp/v2/posts?filter[meta_key]=acfkey&filter[meta_value]=acfvalue');

Custom Post Type
fetch( 'https://domain.com/wp-json/wp/v2/cars?filter[meta_key]=currency&filter[meta_value]=AUD'); // here 'cars' is the endpoint for CPT

Advanced Custom Field
fetch( 'https://domain.com/wp-json/wp/v2/cars?filter[meta_key]=price&filter[meta_compare]=<&filter[meta_value]=200000'); // Query for car 'less' than '200000' in 'price'

Advanced Custom Field – Date (before, equal & after)
fetch( 'https://domain.com/wp-json/wp/v2/cars?filter[meta_key]=expiry_date&filter[meta_value]=2018-12-27T23:59:59&filter[meta_compare]=< // 'Expiry' Before '2018 Boxing Day ends'

Multiple Meta Queries
fetch( 'https://domain.com/wp-json/wp/v2/cars?filter[meta_query][0][key]=currency&filter[meta_query][0][value]&filter[meta_query][1][key]=country&filter[meta_query][1][value]=Australia'); // here 'cars' is the endpoint for CPT

Contact Us

Based in Sydney, SK8Tech is a innovative company providing IT services to SMEs, including Web Design, App Development and more.

Screenshots

Installation

  1. Upload wp-api-filter.php to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress

FAQ

Installation Instructions
  1. Upload wp-api-filter.php to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
Why do I need WP REST Filter?

If you’re planning on using your WordPress website as a Backend, and you’re consuming RESTful api, you’ll most probably need to filter results on your GET request. This is precisely what this plugin does.

Can I filter for multiple meta queries?

YES! See Description.

Can I Use this plugin to find posts by tags/categories?

Yes, however this is natively supported by WordPress 4.7+. This plugin is not necessary if you¡¯re looking to find posts by tags/categories.

For more info, please see this topic.

Does this work with Custom Post Type?

Yes! This plugin is designed to work with CPT types too!

Does this work with Advanced Custom Field?

Yes! This plugin is designed to work with ACF values too!

There’s a bug, what do I do?

Issues and pull requests are welcome at Github repo.

Contributors & Developers

“WP REST Filter” is open source software. The following people have contributed to this plugin.

Contributors

Translate “WP REST Filter” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

1.1.7

  • Added support for filtering by custom filed date

1.1.2

  • Added support for Multiple Meta Queries

1.0.3

  • Minor README fixes.

1.0.2

  • Minor README fixes.

1.0.1

  • Minor README fixes.

1.0.0

  • Initial Release.