你如何使用关系字段查询Pods CMS?

时间:2013-10-24 13:39:13

标签: wordpress podscms

我有2个由Pods CMS创建的自定义内容类型:战斗和事件。在战斗内容类型中,存在事件的关系字段。如何通过特定事件ID从数据库中选择所有战斗?我尝试手动查询pods关系表,但这给了我不正确的结果。

2 个答案:

答案 0 :(得分:3)

$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

应该这样做,但你要查看特定内容类型案例的'find'文档,因为event.id可能不是你想要的(你可能想要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/

答案 1 :(得分:0)

使用此功能,您可以使用简码轻松显示所有单独的关系字段:

function get_pod_fields($atts) {
    $a = shortcode_atts( array('field' => '', 'pod'=> '', 'relation'=> '', 'type'=>'', 'as'=>'url'), $atts );
    $pod = pods( $a['pod'], get_the_id() );
    $related = $pod->field( $a['relation']);
    $field = get_post_meta( $related['ID'], $a['field'], true );
    
    if($a['type'] == "image") {
        if($a['as'] == "image") {
            $field = '<img src="'.$field = $field['guid'].'"></img>';
        } else {
            $field = $field['guid'];
        }
    } else {
        $field = $field;
    }
    return $field;
}
add_shortcode( 'podfields', 'get_pod_fields' );

[podfields field="profile_picture" type="image" pod="therapy" as="image" relation="therapist"]