![](/img/trans.png)
[英]How to get data by applying condition on relational field using Laravel eloquent relation from MongoDB?
[英]how to get relation field with condition
當我們想獲得一些關系字段時,我們會做
$pod = pods( 'pod_name', get_the_id() );
$related = $pod->field( 'relationship_field' );
並且我得到結果數組1、2 ...的列表,但是我需要獲得relationship_field
其中name="some_name"
。 我怎樣才能做到這一點?
如果相關帖子的標題等於some_name
,則以下內容將檢索名為relationship_field
的相關字段:
$pod = pods('pod_name', get_the_ID());
$params = array(
'WHERE' => "relationship_field.post_title = 'some_name'",
);
$related = $pod->find($params);
您的示例是正確的,但稍作調整后,此示例將更加有用:
// 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' )
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.