Pods - 显示关系帖子的链接

时间:2014-08-18 21:36:06

标签: php wordpress relationship podscms

我正在使用Pods在WordPress中设置自定义帖子类型。

我有两种自定义帖子类型:Car and Garage。在Car中我已经与Garage建立了一个关系领域,因此在编辑Car post时我可以从下拉列表中选择一个Garage帖子。

查看汽车贴子时,我想显示所选车库贴的名称和链接。我该怎么做?

以下是http://pods.io/tutorials/get-values-from-a-custom-relationship-field

的示例
//get Pods object for current post
$pod = pods( 'pod_name', get_the_id() );
//get the value for the relationship field
$related = $pod->field( 'relationship_field' );
//loop through related field, creating links to their own pages
//only if there is anything to loop through
if ( ! empty( $related ) ) {
    foreach ( $related as $rel ) { 
        //get id for related post and put in ID
        //for advanced content types use $id = $rel[ 'id' ];
        $id = $rel[ 'ID' ];
        //show the related post name as link
        echo '<a href="'.get_permalink($id).'">'.get_the_title( $id ).'</a>';
        //get the value for some_field in related post and echo it
    } //end of foreach
} //endif ! empty ( $related )

而不是车库帖子的永久链接,我正在收看几个永久链接到我正在观看的汽车邮件。

任何想法?

0 个答案:

没有答案