Bug #22951 Bug Fixed

search:field_name parameter doesn’t work with unchecked checkbox and ‘not’

Version: 3.5.1 Reporter: James Catt

This is an archived bug report. If you are experiencing a similar issue, upgrade to the latest release and if that does not solve the problem, submit a new bug report

I have a checkbox field called hide_from_search (field_id_334) in my pages channel with a value of ‘yes’. If I run a channel:entries call like so:

{exp:channel:entries channel="pages" search:hide_from_search="not yes"}

…entries where the checkbox is unchecked will not be returned. I’ve done some digging and found that it’s essentially an SQL problem—EE sets the field to NULL in the database when the box is unchecked, but when it runs the search it uses the following query:

SELECT t.entry_id FROM exp_channel_titles AS t
       LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_channel_data AS wd ON wd.entry_id = t.entry_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date < 1486583648  AND (t.expiration_date = 0 OR t.expiration_date > 1486583648) AND t.channel_id IN (3) AND t.status = 'open' AND ( (wd.site_id=1 AND wd.field_id_334 NOT LIKE "%yes%") )ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 10000

…but field_id_334 NOT LIKE "%yes%" won’t’ match NULL values.

I haven’t tested under 3.5.2, but I didn’t see anything in the release notes that sounded like it would affect this.

Also note that this problem didn’t occur under EE 2 (I believe it was setting the unchecked field to blank instead of NULL).

  • PS: The same issue is present in Low Search, which has custom code for handling the search:field_name parameter (that’s how I found it).

    Low came up with an easy fix for his plugin, which you can see in the thread linked below. Including it here in case a similar fix is possible in EE native code.


    James Catt
    08th February, 2017 at 3:27pm
  • Thanks, James, and sorry for the trouble. Yes looks like we should also be checking for NULL there. But we’re not comfortable making this change in 3.x as it may change site behavior and that’s unexpected for minor releases, so we’re going to try to include a fix in 4.0.

    Kevin Cupp
    13th February, 2017 at 2:54pm
  • Fair enough. It might be worth adding a note to the documentation then, so people know they should use a radio button instead of a checkbox to get the desired behaviour.

    James Catt
    13th February, 2017 at 3:06pm
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases