wp-graphql-meta-query
wp-graphql-meta-query copied to clipboard
BETWEEN Type not working, MetaArray value needs to accept Array values?
Hi, thank you for the great work you've did !
I would like to have a query that returns all the "Events" that are happening during the next weekend.
This is the query I've crafted:
query getEvents(
$perpage: Int!
$weekend_start: String!
$weekend_end: String!
$after: String
) {
this_weekend: events(
first: $perpage
after: $after
where: {
metaQuery: {
relation: OR
metaArray: [
{
key: "date_start"
compare: BETWEEN
value: [$weekend_start, $weekend_end]
}
{
key: "date_end"
compare: BETWEEN
value: [$weekend_start, $weekend_end]
}
]
}
}
) {
nodes {
__typename
date
title
}
}
}
I've encountered an "Internal server error" issue. I suspect that is due to the fact that the value property doesn't accept array values.
Would you please help me with this?
@a-zog I'm thinking instead of BETWEEN you might want BEFORE
and AFTER
?
Something like:
metaArray: [
{
key: "date_start"
compare: AFTER
value: $weekend_start
}
{
key: "date_end"
compare: BEFORE
value: $weekend_end
}
]
Or something along those lines?
It does seem that this meta query plugin should accept one or more values for the value
input though, since WP_Query allows it. 🤔
It does seem that this meta query plugin should accept one or more values for the
value
input though, since WP_Query allows it. 🤔
I've suspected that because I've found this code in the MetaArray fields definitions.
$type_registry->register_input_type( $type_name . 'MetaArray', [
'fields' => [
...
'value' => [
'type' => 'String',
'description' => __( 'Custom field value', 'wp-graphql' ),
],
....
]
] );
I can either implement BETWEEN or a combination of OR / AND (example here) so I'm sure that all the cases are covered. None of these would unfortunately work.
$args => array(
'relation' => 'OR',
array(
'relation' => 'AND',
array(
'key' => 'event_date_start',
'value' => $weekend_start,
'compare' => '>='
),
array(
'key' => 'event_date_end',
'value' => $weekend_start,
'compare' => '<='
)
),
array(
'relation' => 'AND',
array(
'key' => 'event_date_start',
'value' => $weekend_end,
'compare' => '>='
),
array(
'key' => 'event_date_end',
'value' => $weekend_end,
'compare' => '<='
)
),
)
);