简体   繁体   中英

how to get relation field with condition

When we want to get some relation field we do

$pod = pods( 'pod_name', get_the_id() );
$related = $pod->field( 'relationship_field' );

and I get list of results array 1, 2 ... but I need to get relationship_field where name="some_name" . How can I do that?

The following will retrieve the related field named relationship_field if the related post has a title equal to some_name :

$pod = pods('pod_name', get_the_ID());
$params = array(
  'WHERE' => "relationship_field.post_title = 'some_name'",
);

$related = $pod->find($params);

You're example was right, but with a minor tweak this will be more useful as an example:

// get the pod record based on current post ID
$pod = pods( 'pod_name', get_the_ID() );

$params = array(
    // be sure to sanitize the value going in, if it's dynamic
    'where' => 'relationship_field.post_title = "Some title"'
);

// find records that match $params
$pod->find( $params );

// loop through records found
while ( $pod->fetch() ) {
    // do something with $pod->field( 'field_name' )
    // or $pod->display( 'field_name' )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM