I have a simple pod with a boolean called featured. Iâm trying to use the find()
method (using the pods()
shortcut) to list all pod entries that have the featured boolean set to true on a page template but I canât get it to work. I found this answer but it’s for the older version and doesn’t seem to work in Pods 2.0. If thereâs a simpler way to do this please inform me what Iâm trying something like this:
$params = array(
'orderby' => 'date DESC',
'where' => 'case_study.has_page = 1',
'limit' => -1
);
$pods = pods( 'case-study', $params );
The error I receive is:
WordPress database error: [Unknown column 'case_study.has_page' in 'where clause']
SELECT DISTINCT 't'.* FROM 'wp_posts' AS 't' LEFT JOIN 'wp_postmeta' AS 'case_study' ON 'case_study'.'meta_key' = 'case_study' AND 'case_study'.'post_id' = 't'.'id' WHERE 'case_study'.'has_page' = 1 AND 't'.'post_type' = "case_study" ORDER BY 't'.'date' DESC, 't'.'menu_order', 't'.'post_title', 't'.'post_date'
Database Error; SQL: SELECT DISTINCT 't'.* FROM 'wp_posts' AS 't' LEFT JOIN 'wp_postmeta' AS 'case_study' ON 'case_study'.'meta_key' = 'case_study' AND 'case_study'.'post_id' = 't'.'id' WHERE 'case_study'.'has_page' = 1 AND 't'.'post_type' = "case_study" ORDER BY 't'.'date' DESC, 't'.'menu_order', 't'.'post_title', 't'.'post_date'; Response: Unknown column 'case_study.has_page' in 'where clause'
It appears that it’s not JOINing/WHEREing to the wp_postmeta
correctlyy but I canât quite figure out how to use the find params to do so. It should should be 'case_study'.'meta_key'='has_page'
amongst other problems. I’ve tried making the field a simple relationship with a Yes/No option but still no luck.
Thank you for any help you can provide! Itâs much appreciated.
If your relationship field is named ‘has_page’ and it’s a simple (custom) then you’ll want to use this:
Found it! When editing the pod I went to the ‘Advanced’ settings tab and under ‘Capability Type’ I set it to ‘Custom’ from ‘Posts.’ Voila, it now works! I suppose this setting tells the
find
calls how to operate on the tables. My final find params were as follows:Thank you so much Scott for being quick and an awesome help!
Final solution:
My original content type was an extension of post which doesn’t seem to play well with relationship fields, at least basic ones, since it appears to assume they generate their own table which they don’t always do. As in this case where, since it was a simple custom relationship, the data was all stored in the
wp_postmeta
table.The best solution I found was to rebuild my pod as an Advanced Content Type. This way, the pod generates a table all to its own so checking booleans can be done with a simple
'where' => 'has_page' = 1
instead of all the relationship complexity. Thanks for all your help Scott.