Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get the metaQuery to run multiple conditionals. There's a bug with map_input_fields. #6

Open
ytwguru opened this issue Aug 29, 2019 · 4 comments · May be fixed by #25
Open

Cannot get the metaQuery to run multiple conditionals. There's a bug with map_input_fields. #6

ytwguru opened this issue Aug 29, 2019 · 4 comments · May be fixed by #25

Comments

@ytwguru
Copy link

ytwguru commented Aug 29, 2019

Probably due to a change in the version, but queries using the metaArray don't work correctly when querying a large conditional statement.

I inspected the meta_query generated and it looks like the code below seems to be causing the issue. (It can be deleted and the function can be modified)

foreach ( $meta_query['metaArray'] as $meta_query_key => $value ) {
   $meta_query[] = [
   $meta_query_key => $value,
   ];
}

The output below is from of the meta_query generated from the current (unchanged code)


[meta_query] => Array  (     
     [0] => Array  (     
         [0] => Array  (           
             [key] => event_dates_0_start_time
             [value] => 2019-08-28 00:00:00
             [compare] => >=  
             [type] => DATETIME
         )               
     )
     [1] => Array  (
         [1] => Array  (
             [key] => event_dates_1_start_time
             [value] => 2019-08-28 00:00:00
             [compare] => >=   
             [type] => DATETIME
         ) 
      )
      [2] => Array  (
          [2] => Array  (
              [key] => event_dates_2_start_time
              [value] => 2019-08-28 00:00:00
              [compare] => >= 
              [type] => DATETIME
         )
      )
  )
@jasonbahl
Copy link
Contributor

@ytwguru can you provide an example of the GraphQL query you were trying to make when you noticed this so that I can replicate?

@ytwguru
Copy link
Author

ytwguru commented Aug 29, 2019

For context.

  • I Have a custom post type - events.
  • I created an ACF field called event_dates using an ACF repeater
  • The repeater has subfields start_time and end_time

Here's the query.

query MyQuery {
  events(
    first: 5, 
    where: {
      metaQuery: {
        relation: OR,
        metaArray: [{
          compare: GREATER_THAN_OR_EQUAL_TO,
          type: DATETIME,
          value: "2019-08-28 00:00:00",
          key: "event_dates_0_start_time"
        }, {
          compare: GREATER_THAN_OR_EQUAL_TO,
          type: DATETIME,
          value: "2019-08-28 00:00:00",
          key: "event_dates_1_start_time"
        }, {
          compare: GREATER_THAN_OR_EQUAL_TO,
          type: DATETIME,
          value: "2019-08-28 00:00:00",
          key: "event_dates_2_start_time"
        }, {
          compare: GREATER_THAN_OR_EQUAL_TO,
          type: DATETIME,
          value: "2019-08-28 00:00:00",
          key: "event_dates_3_start_time"
        }, {
          compare: GREATER_THAN_OR_EQUAL_TO, 
          type: DATETIME, 
          value: "2019-08-28 00:00:00", 
          key: "event_dates_4_start_time"
        }]
      }, 
      orderby: {
        field: DATE, 
        order: ASC
      }
    }
  ) {
    edges {
      node {
        title
        link
      }
    }
  }
}

The query should list current events.
As an aside, I would like to order the results by the start_time if possible (requested feature)

@LucasDemea
Copy link

LucasDemea commented Apr 27, 2023

Same Issue here, with this kind of query :

metaQuery: {
        relation: 'OR,
        metaArray:  [
           {
             key: 'post_subject',
             value: '428',
             compare: 'LIKE',
             type: 'CHAR',
           },
           {
             key: 'post_subject',
             value: '392',
             compare: 'LIKE',
             type: 'CHAR',
           },
           {
             key: 'post_subject',
             value: '352',
             compare: 'LIKE',
             type: 'CHAR',
           },
         ],
}

Where post_subject is a ACF relationship field. The query works fine if I execute it the usual wordpress way. It also works If I execute it with one or 2 conditionals.

I'm using wpgraphql 1.5.9 because of this other issue.

@LucasDemea
Copy link

It works again if I remove these lines :

if ( 2 < count( $meta_query['metaArray'] ) ) {
	unset( $meta_query['relation'] );
}

@LucasDemea LucasDemea linked a pull request Apr 27, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants