Advanced Query by Meta Value

Posts can be queried by meta values as defined in the codex. You should familiarize yourself with these before using this advanced functionality.

When querying on checkbox values, sometimes you may have to use EXISTS or NOT EXISTS instead of 1 and 0. In some cases, unchecked values do not get stored in the database and can not be queried. Neither of these options is very consistent, and you may have to find another way to filter true/false values.

The most common use for a query like this would be

meta_queries

One or more meta key names, comma delimited.

keyname_compare

Possible values are ‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘= 3.5). Values ‘REGEXP’, ‘NOT REGEXP’ and ‘RLIKE’

keyname_value

Depending on the compare option, an array or a single integer. If the compare option is ‘Exists’ or ‘Not Exists’ this value is ignored. If you choose more than one value for compare options that do not accept more than one value, only the first value will be used by the plugin to query posts for the grid.

We’re using our guest author name plugin for this example.

Query Posts where the guest author name ‘exists’

 [featured_image_pro meta_queries = 'sfly_guest_author_names' sfly_guest_author_names_compare ='EXISTS' orderby='meta_value' orderby_meta_key='sfly_guest_author_names' subcaptiontype1='meta' subcaption1='sfly_guest_author_names']

Query posts where the guest author is ‘guest author 1’

[featured_image_pro meta_queries = 'sfly_guest_author_names' sfly_guest_author_names_value ='guest author 1' sfly_guest_author_names_compare ='=']