0

WordPress でカスタム投稿タイプを設定するためにポッドを使用しています。

Car と Garage の 2 つのカスタム投稿タイプがあります。Car では、Garage との関係フィールドを設定したので、Car の投稿を編集するときに、ドロップダウンから利用可能な Garage の投稿の 1 つを選択できます。

車の投稿を表示するときに、選択したガレージの投稿への名前とリンクを表示したいと思います。どうすればいいですか?

以下は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 )

ガレージの投稿へのパーマリンクの代わりに、私が見ている車の投稿へのいくつかのパーマリンクを取得しています。

何か案は?

4

0 に答える 0