This is a revised version of #328 after implementing changes mentioned in #428.
Below is the documentation that can be inserted into the wiki.
customfield_compare - Allows for more advanced filtering by custom fields. Can be used together with customfield_orderby, customfield_name and customfield_value. The accepted syntax is customfield_compare=name,compare,value,type where:
name (required) is the custom field's name
compare (required) is one of: equals, not_equals, lessthan, lessthanequal, greaterthan, greaterthanequal, exists, not_exists
value (optional) is the value to check against, it should not be specified when exists or not_exists comparisons are used
type (optional) is one of NUMERIC, BINARY, CHAR, DATE, DATETIME, DECIMAL, SIGNED, TIME, UNSIGNED. This determines the data type used while comparing values, see MySQL docs for more information. Defaults to CHAR which is fine for most cases but you might want to use NUMERIC when comparing numbers.
multiple queries are allowed using ; as delimiter, e.g. [catlist customfield_compare=name,compare,value,type;name2,compare2,value2,type2]. AND relation applies.
examples
[catlist customfield_compare=myfield,not_equals,Mary] - select all posts that have custom field myfield and its value is not Mary
[catlist customfield_compare=myfield,exists] - select all posts that have the myfield custom field
[catlist customfield_compare=myfield,lessthan,100,NUMERIC] - select all posts that have custom field myfield and its value (interpreted as a number) is less than 100
[catlist customfield_compare=myfield,lessthan,100,NUMERIC;mydate,greaterthanequal,2020-01-01,DATE] - select all posts that have custom field myfield and its value (interpreted as a number) is less than 100 and have custom field mydate and its value (interpreted as a date) is greater than or equal to 2020-01-01
For advanced users: you can use regular expressions in value if you use REGEXP as compare but the pattern cannot contain [, ], ,, ; nor other shortcode-forbidden characters.
This is a revised version of #328 after implementing changes mentioned in #428.
Below is the documentation that can be inserted into the wiki.
customfield_orderby
,customfield_name
andcustomfield_value
. The accepted syntax iscustomfield_compare=name,compare,value,type
where:equals
,not_equals
,lessthan
,lessthanequal
,greaterthan
,greaterthanequal
,exists
,not_exists
exists
ornot_exists
comparisons are usedNUMERIC
,BINARY
,CHAR
,DATE
,DATETIME
,DECIMAL
,SIGNED
,TIME
,UNSIGNED
. This determines the data type used while comparing values, see MySQL docs for more information. Defaults toCHAR
which is fine for most cases but you might want to useNUMERIC
when comparing numbers.;
as delimiter, e.g.[catlist customfield_compare=name,compare,value,type;name2,compare2,value2,type2]
. AND relation applies.[catlist customfield_compare=myfield,not_equals,Mary]
- select all posts that have custom fieldmyfield
and its value is notMary
[catlist customfield_compare=myfield,exists]
- select all posts that have themyfield
custom field[catlist customfield_compare=myfield,lessthan,100,NUMERIC]
- select all posts that have custom fieldmyfield
and its value (interpreted as a number) is less than 100[catlist customfield_compare=myfield,lessthan,100,NUMERIC;mydate,greaterthanequal,2020-01-01,DATE]
- select all posts that have custom fieldmyfield
and its value (interpreted as a number) is less than 100 and have custom fieldmydate
and its value (interpreted as a date) is greater than or equal to 2020-01-01value
if you useREGEXP
ascompare
but the pattern cannot contain[
,]
,,
,;
nor other shortcode-forbidden characters.Resolves #428 Resolves #344