Custom Content Type Manager
GetPostsQuery operator like (2 posts)

  1. Araminho
    Posted 3 years ago #

    Hi. I came across with such difficulty. I am trying to search by custom field, for example color. I am using GetPostsQuery class. I want to use "like" operator -

    $args['meta_key'] = 'color'
     $args['meta_value']['like'] = 'blue'

    But here like operator works as equal operator. I want to find out why.
    I want this query to bring not only blue colors, but also light-blue.
    Also if my field is multi-select, I have to write
    $args['meta_value'] = '["blue", "red"]'
    to get the result I want. But there must be another way, or maybe I am doing something wrong. Please help me with this.

    I am using clean wordpress on the default theme, with no other plugins installed.


  2. fireproofsocks
    Plugin Contributor

    Posted 3 years ago #

    Did you forget some semi-colons there?

    You can use the debug option to print out the SQL query -- that's usually the best way to compare the arguments you use to the query that's generated.

    The multi-fields are stored as JSON encoded arrays. This is intentional -- you can read the wiki about why I chose to do it that way. I felt the pros outweighed the cons, but it does mean you may need to include double-quotes in some of your search terms.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic