1

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.

Community
  • 1
  • 1
Primus202
  • 648
  • 7
  • 24
  • Have you tried this in Pods 2.3? http://pods.io/latest/ http://pods.io/github/ – Scott Kingsley Clark Mar 22 '13 at 18:24
  • Doesn't seem to make a difference. For reference my pod name is 'case_study' and the boolean/relationship field is called 'has_page'. Does anyone know how to use simple (custom) relationship fields in a find call? Thanks! – Primus202 Mar 22 '13 at 18:49

3 Answers3

4

If your relationship field is named 'has_page' and it's a simple (custom) then you'll want to use this:

has_field.meta_value = 1
  • No luck though the error went away. Now I get no results. I tried `'has_page_field'` as well in case you made a typo but the same. I can see the entries in my `wp_postmeta` table as such: `meta_id : 2323, post_id : 4202, meta_key : has_page, meta_value : 1` – Primus202 Mar 22 '13 at 19:13
  • In my uninformed opionion it looks like the `where` argument in `find` might be trying to look for a separate table for the relationship even though it's a simple field. I'm going to try readding the field. – Primus202 Mar 22 '13 at 20:30
  • Maybe it's because everything's being stored in meta? If I make a new pod with it's own tables I think that might do it. – Primus202 Mar 22 '13 at 20:38
2

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:

$params = array(
    'orderby' => 'date DESC',
    'where' => 'has_page.meta_value = 1',
    'limit'   => -1
);
$casestudies = pods( 'case_study', $params );

Thank you so much Scott for being quick and an awesome help!

Primus202
  • 648
  • 7
  • 24
  • Ah crap but when you do that it means you have to manually tie in the normal meta actions like writing, editing, etc. as shown [here](http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types)... – Primus202 Mar 22 '13 at 20:57
  • I still get an error even after switching to custom capability, unknown column item_product_type.meta_value :( – Robert Went Apr 14 '15 at 21:55
1

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.

Primus202
  • 648
  • 7
  • 24