I am using GraphQL in Wordpress as API with this plugin: https://docs.wpgraphql.com/getting-started/custom-fields-and-meta I created custom field and I want to use where clause for boolean attribute but I get all record even those who dont match my where clause
My query looks like this:
query pagesInMenu {
pages(where: { menu: true }) {
edges {
node {
id
menu
title
}
}
}
}
And I get records where menu = false and menu = true ... It is custom field added via PHP code below:
function registerMenu($type) {
register_graphql_field( $type, 'menu', [
'type' => 'Boolean',
'description' => __( 'Is in menu?', 'wp-graphql' ),
'resolve' => function( $post ) {
$menu = get_post_meta( $post->ID, 'menu', true );
return ! empty( $menu ) ? ($menu == "true") : false;
}
] );
}
add_action( 'graphql_register_types', registerMenu('Page') );
add_action( 'graphql_register_types', registerMenu('RootQueryToPageConnectionWhereArgs') );