Search code examples
wordpresspodscms

How do you query Pods CMS using relationship field?


I have 2 custom content types created by Pods CMS: fights and events. In the fights content type there is a relationship field for the event. How would I select all fights from the database by a specific event id? I tried querying the pods relationships table manually but that gave me incorrect results.


Solution

  • $fights = pods( 'fights' );
    
    $params = array(
        'where' => 'event.id = 3'
    );
    
    $fights->find( $params );
    
    // loop through a while( $fights->fetch() ) and use $fights->field() to get the values of each field
    

    That should do it, but you'll want to look at the 'find' documentation for your specific content type case as event.id may not be what you want (you may want event.ID).

    http://pods.io/docs/code/pods/

    http://pods.io/docs/code/pods/find/

    http://pods.io/docs/code/pods/field/

    http://pods.io/docs/code/pods/display/