Title: Arrrgh&#8230; help, please!
Last modified: August 21, 2016

---

# Arrrgh… help, please!

 *  Resolved [CodeMonkey613](https://wordpress.org/support/users/codemonkey613/)
 * (@codemonkey613)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/)
 * Been stuck on this over two hours. Please, someone help!!!
 * 1) First problem: I created a pod “products” as a “Custom Post Type”. Has a field“
   product_price” that is “Currency” (field type). When I “order by”, it behaves
   like text, ordering like: $0.00, $1000, $200, $300, $5.
 *     ```
       $products = pods('products', array(
              'page' => 1,
              'limit' => 10,
              'orderby' => 'product_price ASC',
              'where' => "post_status = 'publish'"
           ));
       ```
   
 * 2) Second problem: I get error when searching by keywords. I have another field
   called “product_gender”, it’s a “Relationship” (field type) as “Simple Custom
   Defined List” (options are: Unknown, Male, Female). When I add “where clause”,
   SQL throws error: “Unknown column ‘product_gender’ in ‘where clause’. How am 
   I supposed to do this correctly?
 *     ```
       $products = pods('products', array(
              'page' => 1,
              'limit' => 10,
              'orderby' => 'ID ASC',
              'where' => "post_status = 'publish' AND (post_title like '%male%' AND product_gender like '%male%')"
           ));
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Contributor [pglewis](https://wordpress.org/support/users/pglewis/)
 * (@pglewis)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125580)
 * try: CAST(product_price AS DECIMAL) in your orderby
 * Post meta is always stored as a string since meta_value is a longtext field in
   wp_postmeta. Casting it to a decimal type before the sort should work around 
   that.
 *  Thread Starter [CodeMonkey613](https://wordpress.org/support/users/codemonkey613/)
 * (@codemonkey613)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125584)
 * Hi pglewis, thank you for the quick response. I tried ABS() before and couldn’t
   get it working. Upon your suggestion, I tried CAST() and got an error. But with
   minor modification I got it working:
 *     ```
       CAST(product_price.meta_value AS DECIMAL)
       ```
   
 * Do you maybe have suggestion for my “second problem” too? Thanks.
 *  Plugin Contributor [pglewis](https://wordpress.org/support/users/pglewis/)
 * (@pglewis)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125585)
 * On problem 2: I think it should be product_gender.meta_value
 * There is a very handy chart for these situations here:
 * [http://pods.io/docs/code/pods/find/](http://pods.io/docs/code/pods/find/)
 * The first column, 4th row of the table at the bottom of the page covers your 
   scenario.
 *  Thread Starter [CodeMonkey613](https://wordpress.org/support/users/codemonkey613/)
 * (@codemonkey613)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125589)
 * Hi pglewis, this case it doesn’t seem to help adding “meta_value”. It no longer
   throws the error, but it returns 0 results. Could it be because the field is 
   a “Relationship / Simple (custom defined list)”?
 * I’ve got it filtering the “post_title” using keywords correctly. But it won’t
   recognize the contents of this “product_gender” field.
 *  Plugin Contributor [pglewis](https://wordpress.org/support/users/pglewis/)
 * (@pglewis)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125596)
 * I’m not sure right off the bat. Try adding ?pods_debug_sql=1 to the URL (or &
   pods_debug_sql=1 if there are already URL params) to see the exact query Pods
   is running. That should give some insight.
 *  Thread Starter [CodeMonkey613](https://wordpress.org/support/users/codemonkey613/)
 * (@codemonkey613)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125608)
 * Awesome, that helped a lot, thanks! Turns out that because I was using the query
   variable $search, pods was automatically using that to query the post_title, 
   resulting in a SQL statement of “product_gender like ‘%male%’ AND post_title 
   like ‘%male%'”. So I was getting 0 results because there is no point at which
   gender AND title both have the keyword.
 * So I just needed to change the variable from $search to $keywords so that pods
   would stop writing the $where statement automatically.
 * I also notice pods handles “post_status IN (‘publish’)” by itself, so I was needlessly
   adding that a second time.
 * Thanks so much! Took 4 hours but can finally relax lol 🙂
 *  Plugin Contributor [pglewis](https://wordpress.org/support/users/pglewis/)
 * (@pglewis)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125734)
 * Glad you were able to get it ironed out. That URL param is definitely handy when
   you start troubleshooting more complex queries.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Arrrgh… help, please!’ is closed to new replies.

 * ![](https://ps.w.org/pods/assets/icon.svg?rev=3286397)
 * [Pods - Custom Content Types and Fields](https://wordpress.org/plugins/pods/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/pods/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/pods/)
 * [Active Topics](https://wordpress.org/support/plugin/pods/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pods/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pods/reviews/)

## Tags

 * [currency](https://wordpress.org/support/topic-tag/currency/)
 * [Failed](https://wordpress.org/support/topic-tag/failed/)
 * [order by](https://wordpress.org/support/topic-tag/order-by/)
 * [sort](https://wordpress.org/support/topic-tag/sort/)

 * 7 replies
 * 2 participants
 * Last reply from: [pglewis](https://wordpress.org/support/users/pglewis/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/arrrgh-help-please/#post-5125734)
 * Status: resolved