WPGraphQL Extension: Adds "meta_query" support to postObject connection queries using WP_Query

Overview

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 );
Comments
  • Fatal error: Uncaught ArgumentCountError: Too few arguments to function

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function

    Hi, thank you for the very good plugins, they are really useful.

    Anyway, at the moment I get this error (on mywpsite.com/graphql with wp in debug mode)

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function WPGraphQL\MetaQuery::add_input_fields(), 3 passed in /home/mywpsite/public_html/admin/wp-includes/class-wp-hook.php on line 288 and exactly 4 expected in /home/mywpsite/public_html/admin/wp-content/plugins/wp-graphql-meta-query-develop/wp-graphql-meta-query.php:139
    Stack trace:
    #0 /home/mywpsite/public_html/admin/wp-includes/class-wp-hook.php(288): WPGraphQL\MetaQuery->add_input_fields(Array, 'UserToAwardConn...', Array)
    #1 /home/mywpsite/public_html/admin/wp-includes/plugin.php(206): WP_Hook->apply_filters(Array, Array)
    #2 /home/mywpsite/public_html/admin/wp-content/plugins/wp-graphql-develop/src/Type/WPInputObjectType.php(40): apply_filters('graphql_input_f...', Array, 'UserToAwardConn...', Array)
    #3 /home/mywpsite/public_html/admin/wp-content/plugins/wp-graphql-develop/src/Registry/TypeRegistry.php(440): WPGraphQL\Type\WPInputObjectType::prepare_fields(Array, 'UserToAwardConn...')
    #4 [internal function]: WPGraphQL\Registry\TypeRegistry->WPGraphQL\Registr in /home/mywpsite/public_html/admin/wp-content/plugins/wp-graphql-meta-query-develop/wp-graphql-meta-query.php on line 139
    

    and look like is referring to this php function in the plugin

    public function add_input_fields( $fields, $type_name, $config, $type_registry ) {
        if ( isset( $config['queryClass'] ) && 'WP_Query' === $config['queryClass'] ) {
            $this->register_types( $type_name, $type_registry );
            $fields['metaQuery'] = [
                'type' => $type_name . 'MetaQuery',
            ];
        }
        return $fields;
    }
    

    I've disabled all plugins and activated only wp-graphql and wp-graphql-meta-query but still the error is breaking the wp-graphql functionalities. I've almost the same configuration in another site and is working fine. What I'm doing wrong?

    opened by supermodo 4
  • Could not scan for classes inside

    Could not scan for classes inside "/wp-graphql-meta-query//src/" which does not appear to be a file nor a folder

    "Could not scan for classes inside "frontend/wp-content/plugins/wp-graphql-meta-query//src/" which does not appear to be a file nor a folder"

    Error message happinging, when installing using composer.

    In composerfile, there is a reference to

      "autoload": {
        "psr-4": {
          "WPGraphQL\\MetaQuery\\": "src"
        },
        "classmap": [
          "src/"
        ]
    

    But there is no src folder anymore. Could this just be deleted?

    Src folder, was deleted in this commit https://github.com/wp-graphql/wp-graphql-meta-query/commit/4db3cf9411995c7a14399f2d45986ce64af554b3

    opened by jespervnielsen 2
  • Uncaught ArgumentCountError: Too few arguments to function WPGraphQL\MetaQuery::add_input_fields()

    Uncaught ArgumentCountError: Too few arguments to function WPGraphQL\MetaQuery::add_input_fields()

    I just updated 1.0.0 and now get this error.

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function WPGraphQL\MetaQuery::add_input_fields(), 3 passed in /www/wp-includes/class-wp-hook.php on line 286 and exactly 4 expected in /www/wp-content/plugins/wp-graphql-meta-query/wp-graphql-meta-query.php:139 Stack trace: #0 /www/wp-includes/class-wp-hook.php(286): WPGraphQL\MetaQuery->add_input_fields(Array, 'RootQueryToCate...', Array) #1 /www/wp-includes/plugin.php(208): WP_Hook->apply_filters(Array, Array) #2 /www/wp-content/plugins/wp-graphql/src/Type/WPInputObjectType.php(40): apply_filters('graphql_input_f...', Array, 'RootQueryToCate...', Array) #3 /www/wp-content/plugins/wp-graphql/src/Registry/TypeRegistry.php(440): WPGraphQL\Type\WPInputObjectType::prepare_fields(Array, 'RootQueryToCate...') #4 [internal function]: WPGraphQL\Registry\TypeRegistry->WPGraphQL\Registry\{closure}() #5 /www/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Definition/InputObjectType.php(50): call_user_func(Object(Closure)) #6 /www/wp-content/plugins/wp- in /www/wp-content/plugins/wp-graphql-meta-query/wp-graphql-meta-query.php on line 139 
    
    opened by drewbaker 1
  • How to query latitude and logitud from a Google Maps field?

    How to query latitude and logitud from a Google Maps field?

    I have a Google Maps field and I would like to query by the location. My field is called "itemLocation". What should I use as the "key"? Because the following does not work:

    metaQuery: { relation: AND metaArray: [ { key: "itemLocation['latitude']", compare: BETWEEN, value: [$latitude_start, $latitude_end] }, { key: "itemLocation['longitude']", compare: BETWEEN, value: [$latitude_start, $latitude_end] } ] }

    opened by aldoalfaro 0
  • Not possible to simply retrieve meta data for a post?

    Not possible to simply retrieve meta data for a post?

    Hi,

    I am new to wpgraphql and your plugin - but as far as I can tell your plugin supports querying on meta data but what I want to do is simply retrieve the meta data associated with a specific post or posts.

    Thanks

    opened by Wolsten 0
  • Pass array of values for same key?

    Pass array of values for same key?

    @jasonbahl I am trying to pass multiple values for the same key but cannot get any posts back

    metaArray: [
              {
                key: "some_key",
                value:  ["some_value", "some_other_value"],
                compare: EXIST
              }
            ]
    

    is something like this possible?

    opened by web-programmer-here 0
  • Meta Query with multiple conditions

    Meta Query with multiple conditions

    Is it possible to add a meta query with multiple conditions?

    I only want the posts where: meta_key_1 OR meta_key_2 NOT_EQUAL_TO null AND meta_key_3 is greater then X

    opened by HHarsevoord 0
  • v0.1.1 lists out

    v0.1.1 lists out "0.1.0" in plugins

    v0.1.1 still says that it is v0.1.0 on the WP Plugins page. I believe the PHP Docs just need to be updated to reflect the new version: https://github.com/wp-graphql/wp-graphql-meta-query/blob/v0.1.1/wp-graphql-meta-query.php#L2-L18

    opened by mdrayer 0
Releases(v0.1.1)
Owner
WPGraphQL
An Open Source WordPress plugin that enables a GraphQL API for WordPress sites
WPGraphQL
An WPGraphQL extension that adds SearchWP's query functionality to the GraphQL server

QL Search What is QL Search? An extension that integrates SearchWP into WPGraphQL. Quick Install Install & activate SearchWP v3.1.9+ Install & activat

Funkhaus 11 May 5, 2022
Enable query locking for WPGraphQL by implementing persisted GraphQL queries.

?? WP GraphQL Lock This plugin enables query locking for WPGraphQL by implementing persisted GraphQL queries. Persisted GraphQL queries allow a GraphQ

Valu Digital 21 Oct 9, 2022
[ALPHA] Implementation of persisted queries for WPGraphQL

WPGraphQL Persisted Queries Persisted GraphQL queries allow a GraphQL client to optimistically send a hash of the query instead of the full query; if

Quartz 18 Jun 20, 2022
Wordpress wrapper to expose Carbon Fields to WpGraphQL queries.

WpGraphQLCrb A Wordpress wrapper to expose Carbon Fields to WpGraphQL queries. Important This is just the first version. There is a lot of work to be

Matheus Paiva 16 Aug 19, 2022
Adds Settings to the Custom Post Type UI plugin to show Post Types in WPGraphQL

DEPRECATION NOTICE ?? Custom Post Type UI v1.9.0 introduced formal support for WPGraphQL!!! ?? With that, this plugin is being deprecated and will no

WPGraphQL 77 Aug 3, 2022
WPGraphQL Polylang Extension for WordPress

WPGraphQL Polylang Extension Extend WPGraphQL schema with language data from the Polylang plugin. Features For posts and terms (custom ones too!) Adds

Valu Digital 102 Dec 29, 2022
This is an extension to the WPGraphQL plugin for Yoast SEO

WPGraphQl Yoast SEO Plugin Please note version 14 of the Yoast Plugin is a major update. If you are stuck on version of Yoast before V14 then use v3 o

Ashley Hitchcock 197 Dec 26, 2022
Add WooCommerce support and functionality to your WPGraphQL server

WPGraphQL WooCommerce (WooGraphQL) Docs • AxisTaylor • Join Slack Quick Install Install & activate WooCommerce Install & activate WPGraphQL Download t

WPGraphQL 546 Jan 2, 2023
Authentication for WPGraphQL using JWT (JSON Web Tokens)

WPGraphQL JWT Authentication This plugin extends the WPGraphQL plugin to provide authentication using JWT (JSON Web Tokens) JSON Web Tokens are an ope

WPGraphQL 268 Dec 31, 2022
Send emails via mutation using WpGraphQl

WPGraphQL Send Email Plugin One of the simple things about a traditional WordPress sites is sending emails, this plugin makes it easy to do this via a

Ashley Hitchcock 18 Aug 21, 2022
Structured content blocks for WPGraphQL

WPGraphQL Content Blocks (Structured Content) This WPGraphQL plugin returns a WordPress post’s content as a shallow tree of blocks and allows for some

Quartz 72 Oct 3, 2022
a wordpress plugin that improves wpgraphql usage together with wpml

WPGraphQL WPML Extension Contributors: rburgst Stable tag: 1.0.6 Tested up to: 5.6.1 Requires at least: 4.9 Requires PHP: 7.0 Requires WPGraphQL: 0.8.

null 42 Dec 15, 2022
WPGraphQL for Advanced Custom Fields

WPGraphQL for Advanced Custom Fields WPGraphQL for Advanced Custom Fields automatically exposes your ACF fields to the WPGraphQL Schema. Install and A

WPGraphQL 558 Jan 8, 2023
WPGraphQL FacetWP integration plguin

WPGraphQL-FacetWP: WPGraphQL provider for FacetWP Quick Install Download and install like any WordPress plugin. Documentation The WPGraphQL documentat

null 31 Dec 11, 2022
WPGraphQL for Meta Box

WPGraphQL-MetaBox: WPGraphQL provider for Meta Box Quick Install Download and install like any WordPress plugin. Documentation The WPGraphQL documenta

null 25 Aug 8, 2022
Querycase provides a convenient, fluent interface for creating and running database queries in WordPress.

Querycase database for WordPress Dependency-free library to create SQL Queries in WordPress. Explore the documentation → ℹ️ About Querycase Querycase

Alessandro Tesoro 7 Oct 17, 2021
Adds meta data registered via register_meta() to the GraphQL output.

WP GraphQL Meta This plugin is an add-on for the awesome WP GraphQL It builds on top of both WP GraphQL and the REST API. Any meta data you register u

Robert O'Rourke 18 Aug 4, 2021
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Contact us for any customization: contact@binsh

Binshops 279 Dec 28, 2022
Simple Wordpress plugin that adds social share buttons

Super Fast Social Share Simple Wordpress plugin that adds social share buttons to Wordpress posts. ?? Screenshots You can either load the default css

Matthew Kiggen 2 Nov 8, 2021