WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 6 months ago

#22967 new defect (bug)

Null value in meta query changes the type of comparison

Reported by: bradyvercher Owned by:
Priority: normal Milestone: Awaiting Review
Component: Query Version: 3.5
Severity: normal Keywords: has-patch
Cc: scribu

Description

If a null value is set in a meta query, it effectively returns the same results as setting the 'compare' arg to 'EXISTS', even if it's explicitly set to the default '='.

For example:

$value_var = null;
...
meta_query => array(
        array(
            'key'     => '_my_meta_key',
            'value'   => $value_var,
            'compare' => '='
        )
    )
...

That returns all rows where '_my_meta_key' exists and ignores 'value' instead of treating it like an empty string. This can be troublesome where the value is passed in dynamically like the example, so validation would have to be done prior to every meta query to ensure the value isn't null.

I've attached a patch for review that checks for the existence of the 'value' key rather than using isset and casts it to a string if it's null.

Attachments (1)

22967.patch (921 bytes) - added by bradyvercher 6 months ago.

Download all attachments as: .zip

Change History (3)

bradyvercher6 months ago

comment:1 scribu6 months ago

  • Cc scribu added

comment:2 SergeyBiryukov6 months ago

  • Version changed from trunk to 3.5

Related: [22103] (for #19729).

Note: See TracTickets for help on using tickets.