0

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

4

2 回答 2

4
$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

应该这样做,但是您需要查看特定内容类型案例的“查找”文档,因为 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/

于 2013-10-29T09:57:03.270 回答
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" 关系="治疗师"]

于 2021-04-19T10:40:56.120 回答