当我们想要获得一些关系字段时,我们
$pod = pods( 'pod_name', get_the_id() );
$related = $pod->field( 'relationship_field' );
我得到结果列表1,2 ...
但我需要relationship_field
name="some_name"
。我怎么能这样做?
答案 0 :(得分:1)
如果相关帖子的标题等于relationship_field
,则以下内容将检索名为some_name
的相关字段:
$pod = pods('pod_name', get_the_ID());
$params = array(
"WHERE" => "relationship_field.post_title = 'some_name'"
);
$related = $pod->find( $params );
答案 1 :(得分:0)
你的榜样是正确的,但通过一个小调整,这将是一个更有用的例子:
// 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' )
}