当我们想要获得一些关系字段时,我们会这样做
$pod = pods( 'pod_name', get_the_id() );
$related = $pod->field( 'relationship_field' );
我得到了结果数组 1、2 的列表……但我需要得到relationship_field
where name="some_name"
。我怎样才能做到这一点?
relationship_field
如果相关帖子的标题等于 ,则以下将检索命名的相关字段some_name
:
$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' )
}