Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wp-graphql/wp-graphql-meta-query
WPGraphQL Extension: Adds "meta_query" support to postObject connection queries using WP_Query
https://github.com/wp-graphql/wp-graphql-meta-query
Last synced: 2 months ago
JSON representation
WPGraphQL Extension: Adds "meta_query" support to postObject connection queries using WP_Query
- Host: GitHub
- URL: https://github.com/wp-graphql/wp-graphql-meta-query
- Owner: wp-graphql
- License: gpl-3.0
- Created: 2017-02-14T17:28:56.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2023-04-27T17:06:44.000Z (over 1 year ago)
- Last Synced: 2024-04-14T11:00:58.242Z (9 months ago)
- Language: PHP
- Homepage: https://wpgraphql.com
- Size: 81.1 KB
- Stars: 49
- Watchers: 6
- Forks: 18
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wpgraphql - WPGraphQL Meta Query
- awesome-wordpress-gatsby - WPGraphQL Meta Query - Adds Meta_Query support to the WPGraphQL Plugin for postObject query args. (Plugins / WordPress)
README
# WPGraphQL Meta Query
This plugin adds Meta_Query support to the WP GraphQL Plugin for postObject query args.## Why is this an extension and not part of WPGraphQL?
Meta Queries _can_ be expensive and have been known to actually take sites down, which is why they are not
part of the core WPGraphQL plugin.If you need meta queries for your WPGraphQL system, this plugin enables them, but use with caution. It might be better
to hook into WPGraphQL and define specific meta queries that you _know_ you need and are not going to take your system
down instead of allowing just any meta_query via this plugin, but you could use this plugin as an example of how
to hook into WPGraphQL to add inputs and map those inputs to the WP_Query that gets executed.## Pre-req's
Using this plugin requires having the WPGraphQL plugin installed
and activated. Requires WPGraphQL version 0.0.15 or newer.## Activating / Using
Activate the plugin like you would any other WordPress plugin.Once the plugin is active, the `metaQuery` argument will be available to any post object connectionQuery
(posts, pages, custom post types, etc).## Example Query
Below is an example Query using the metaQuery input on a `posts` query. (Go ahead and check things out in GraphiQL)This will find `posts` that have `some_value` as the value of the post_meta field with the key of `some_key` AND also
DOES NOT have `some_other_value` as the value for the post_meta key `some_other_key````
query{
posts(
where: {
metaQuery: {
relation: AND
metaArray: [
{
key: "some_key",
value: "some_value"
compare: EQUAL_TO
},
{
key: "some_other_key",
value: "some_other_value",
compare: NOT_EQUAL_TO
}
]
}
}
){
edges{
cursor
node{
id
postId
link
date
}
}
}
}
```The same query in PHP using WP_Query would look like:
```
$args = [
'meta_query' => [
'relation' => 'AND',
[
'key' => 'some_key',
'value' => 'some_value',
'compare' => 'EQUAL TO',
],
[
'key' => 'some_other_key',
'value' => 'some_other_value',
'compare' => 'NOT EQUAL TO',
],
],
];new WP_Query( $args );
```