Quantcast
Channel: Question and Answer » meta-query
Viewing all articles
Browse latest Browse all 36

Use REGEXP in WP_Query meta_query key

$
0
0

I know I can use REGEXP in WP_Query like this:

$query = new WP_Query(array(
  'posts_per_page'    => -1,
  'post_status'       => 'publish',
  'meta_query'        => array(
    array(
      'key'     => 'custom_fields',
      'value'   => 'foo[(][0-9][)]', // with regex stuff
      'compare' => 'REGEXP',
    ),
  ),
));

But I need regular expressions in the key too. Like this:

$query = new WP_Query(array(
  'posts_per_page'    => -1,
  'post_status'       => 'publish',
  'meta_query'        => array(
    array(
      'key'     => 'custom_fields[(][0-9][)]', // with regex stuff
      'value'   => 'foo',
      'compare' => 'REGEXP',
    ),
  ),
));

Is there any way to achieve this with a filter maybe? Or do I have to build it all myself with an own SQL query?


Viewing all articles
Browse latest Browse all 36

Trending Articles