Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#42397 closed defect (bug) (worksforme)

% symbol don't work anymore in args of wp_query

Reported by: pactivis132's profile pactivis132 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8.3
Component: Query Keywords:
Focuses: Cc:

Description

Hello,

Yesterday, after the update 4.8.3 of Wordpress, in the argument for wp_query, the % symbol don't work anymore. Actually, it is when we try to push this type of structure : 'meta_key' => 'deadlines_%_date', it don't work. It generate an error.

Change History (4)

#1 @mariovalney
7 years ago

  • Version set to trunk

I'm trying to reproduce the problem, but I couldn't. Can you provide more information on how you are using '%' before 4.8.3?

Actually, I created a 4.7.7 install and two new posts with "teste" meta_key and differente values.

This query shows both:

<?php
$query = new WP_Query( array(
        'post_type'             => 'post',
        'meta_key'              => 'teste',
) );

But this don't show nothing:

$query = new WP_Query( array(

<?php
        'post_type'             => 'post',
        'meta_key'              => 'test%',
) );

Not even with LIKE compare:

<?php
$query = new WP_Query( array(
        'post_type'             => 'post',
        'meta_key'              => 'test%',
        'meta_compare'          => 'LIKE',
) );

(Same behaviour trying '%' in meta_value - LIKE compare is for them after all - and trying both tests in 4.8.3 version)

Sorry if I misunderstood your point.

Version 1, edited 7 years ago by mariovalney (previous) (next) (diff)

#2 @Clorith
7 years ago

  • Version changed from trunk to 4.8.3

#3 @Otto42
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

WordPress core does not support, and has never supported, meta_key's that contain wildcards because WordPress always uses an = comparison for the meta_key, never a LIKE comparison.

It is true that some users use plugins or other custom code to convert that = into a LIKE for those % cases. The change to the way queries work in 4.8.3 will probably break that existing code. This cannot be avoided. The plugin or custom code will need to be changed to accommodate this.

Note that plugins or custom code that uses the "query" filter can see the full SQL string, as it will run, without the new changes in 4.8.3. This will include the percent signs as previously. Code that uses this filter will be unaffected and continue to work correctly. Code that used other filters will not see % signs in their filter input any longer, and should be modified to not be looking for the % sign specifically.

Note: See TracTickets for help on using tickets.