Select posts using @wordpressdata with query based on custom field always returns all records

admin2025-01-07  4

I am trying to select records that have a custom field value that matches a search condition but the result is always all records

To register the custom field for my post type I am using the following code

register_post_meta(
  'my_post_type',
  'my_data',
  array(
    'show_in_rest' => true,
    'single' => true,
    'type' => 'integer',
  )
)

To query the posts:

const data = useSelect((select) => {
  const metaQuery = [
    {
      key: 'my_data',
      value: [50, 100],
      compare: 'BETWEEN',
      type: 'NUMERIC'
    }
  ];
  return select(coreDataStore).getEntityRecords('postType', 'my_post_type', { meta_query: metaQuery });
});

but I am always receiving all records with my custom posts and zero errors or warnings. The metadata field is presented in the results. Generated request to the server contains the meta_query part, but it is url encoded. This is probably a reason why meta_query is ignored.

What did I miss?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736264091a940.html

最新回复(0)