Hi Martin,
The link from the inline help does goes a few additional links deep before showing the field syntax for a WHERE query, but eventually ends up at https://docs.pods.io/code/pods/find/find-reference-table/#Field_Syntax_Reference, which generally says that fields in the main table, such as wp_posts
are prefixed with t.
, meta fields are annotated as field_name.meta_value
, and meta fields using table-based storage (not advanced content types) are prefixed with d.
Here are some examples for a WHERE
filter on a relationship field. In this case, the relationship field is on the post
post type, and also relates to post
(it’s a relationship field which relates to its own type):
t.post_title LIKE '%Example%'
Only show posts which have a Post Title that contains the capitalized word Example
. This is a MySQL LIKE query, where %
stands for any number of characters, and _
stands for any single character.
t.ID IN( 1, 74 )
Display only Posts of the related post_type
where the ID is either 1
(the first post, “Hello World”), or 74
.
plain_text_field.meta_value = 'ABC'
Display only posts where a Plain Text field named plain_text_field
has the exact value ABC
taxonomy_relationship_field.slug IN( 'dog', 'puppy' )
For a relationship field to a taxonomy named taxonomy_relationship_field
, display only posts where that field is associated with a term where the term slug
is either dog
or puppy
CAST( t.post_date AS DATETIME ) BETWEEN ( NOW() - INTERVAL 14 DAY ) AND ( NOW() + INTERVAL 1 DAY )
Display only posts whose publish date is between two weeks ago and tomorrow.
show_in_the_menu.meta_value = "1"
Display only posts which have a Yes/No
field named show_in_the_menu
which has been checked.
t.post_status = "publish" AND t.post_title LIKE "Example%"
Display posts which have been published AND
whose title begins with the word Example
with a capital E.
LOWER( t.post_title ) LIKE "%example%"
Display posts where the title contains the word example
with any variation of capitalization.
More information on fields available for posts, meta, taxonomy terms, and users in the default WordPress database schema can be found at https://codex.www.ads-software.com/Database_Description
More information on using CAST()
for time-based searches can be found at https://docs.pods.io/searching-filtering-sorting/complicated-where-sort-and-filters/using-date-based-searches/
More information on MySQL WHERE statements can be found at https://www.mysqltutor.com/mysql-where/ and https://www.geeksforgeeks.org/mysql-where-clause/, among other documentation for MySQL generally.
Documentation on CAST()
can be found at https://www.w3schools.com/sql/func_mysql_cast.asp — it is worth noting that most WordPress meta fields are stored as text. So while CAST
is most frequently used for converting text to time-based values, it may also be useful for cases where mathematical comparisons are desired, such as <
or >
, where it may be necessary to cast a field as DECIMAL
.