Querying by a pod field

5k Views Asked by At

I have a custom pod, product_type, in that pod I have a custom field named label. I want to find all the pods where the label matches a certain strings.

Iv been trying this (and some other variations):

$mypod = pods('product_type', array(
    'where'   => 'product_type.label LIKE "%'.$someLabelString.'%"',
    'limit'=>-1
));

I've also tried changing the product_type.label part of the query to t.label, but to no avail. I get this error:

Database Error; SQL: SELECT DISTINCT `t`.* FROM `wp_posts` AS `t` WHERE ( ( `product_type`.`label` LIKE "%hello%" ) AND ( `t`.`post_type` = "product_type" ) AND ( `t`.`post_status` IN ( "publish" ) ) ) ORDER BY `t`.`menu_order`, `t`.`post_title`, `t`.`post_date`; Response: Unknown column 'product_type.label' in 'where clause'
1

There are 1 best solutions below

1
On

Here’s a super handy break down of what field syntax to use for each pod type:

http://pods.io/docs/code/pods/find/#additional-information

Custom simple lists consist of a label (for display) and a value (the underlying “raw” value). For the ‘where’ parameter, you probably need to check against whatever you set as the ‘value’.

When you create a simple custom defined list, a box becomes available for “Custom Defined Options”. As the help pop-up says: “One option per line, use value|Label for separate values and labels”

If you added the label field to your pod, you would just use product_type.label if your pod is table-based for storage, otherwise if it’s meta-based you would use label.meta_value