Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wp-graphql/wp-graphql-tax-query
Adds `tax_query` support to postObject connection queries using WP_Query
https://github.com/wp-graphql/wp-graphql-tax-query
Last synced: about 1 month ago
JSON representation
Adds `tax_query` support to postObject connection queries using WP_Query
- Host: GitHub
- URL: https://github.com/wp-graphql/wp-graphql-tax-query
- Owner: wp-graphql
- Created: 2017-02-14T17:29:22.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2022-11-08T17:13:28.000Z (about 2 years ago)
- Last Synced: 2024-04-14T06:53:41.691Z (8 months ago)
- Language: PHP
- Size: 35.2 KB
- Stars: 46
- Watchers: 6
- Forks: 16
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-wpgraphql - WPGraphQL Tax Query
- awesome-wordpress-gatsby - WPGraphQL Tax Query - Adds Tax_Query support to the WPGraphQL Plugin for postObject query args (WP_Query). (Plugins / WordPress)
README
# WPGraphQL Tax Query
This plugin adds Tax_Query support to the WP GraphQL Plugin for postObject query args (WP_Query).
## Pre-req's
Using this plugin requires having the WPGraphQL plugin installed
and activated. (version 0.0.15 or newer)## Activating / Using
Activate the plugin like you would any other WordPress plugin.Once the plugin is active, the `taxQuery` argument will be available to any post object connectionQuery
(posts, pages, custom post types, etc).## Example Query
Below is an example Query using the taxQuery input on a `posts` query. (Go ahead and check things out in
GraphiQL)This will find `posts` that are in the category "graphql" OR tagged with "wordpress".
```
query{
posts(
where: {
taxQuery: {
relation: OR,
taxArray: [
{
terms: ["graphql"],
taxonomy: CATEGORY,
operator: IN,
field: SLUG
},
{
terms: ["wordpress"],
taxonomy: TAG,
operator: IN,
field: SLUG
}
]
}
}
){
edges{
cursor
node{
id
postId
link
date
}
}
}
}
```The same query in PHP using WP_Query would look like:
```
$args = [
'tax_query' => [
'relation' => 'OR',
[
'terms' => ['graphql'],
'taxonomy' => 'category',
'operator' => 'IN',
'field' => 'slug',
],
[
'terms' => ['wordpress'],
'taxonomy' => 'post_tag',
'operator' => 'IN',
'field' => 'slug',
],
],
];new WP_Query( $args );
```