Pod findRecords relationship

I create items using pods, I want to filter through the pods depending on what their relationship is.

Eg I have 2 relationships to pick from: “Good” or “Bad”

Read More
$pods_name = "attitude";
//get the specific pod object:
$thePod = new Pod($pods_name);
$thePod->findRecords(-1, "attitude.mood = Good");
//mood is the label of the relationship you can choose from (has
//the options between good or bad)

The problem with this is that it returns items in both Good and Bad.
I can’t see how they’re linked in the database, is there a more specific way you have to call it to find the records of only items listed under “Good”?

Related posts

Leave a Reply

1 comment

  1. findRecords uses MySQL queries, you need to put your Good text into quotes.

    Also, follow the documentation used at: http://podscms.org/codex/findrecords/

    You likely are looking to use this code:

    $thePod->findRecords('t.name', -1, 'attitude.mood = "Good"');
    

    Though I suggest using the $params method:

    $thePod->findRecords(array('orderby' => 't.name', 'limit' => -1, 'where' => 'attitude.mood = "Good"'));
    

    Also, before putting something into findRecords dynamically (user-input), be sure to run esc_sql($value) on it before placing it into findRecords