text PODS从关系字段中获取值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text PODS从关系字段中获取值相关的知识,希望对你有一定的参考价值。

<?php 
    	//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="'.esc_url( get_permalink( $id ) ).'">'.get_the_title( $id ).'</a>';
			//get the value for some_field in related post and echo it
			$someField = get_post_meta( $id, 'some_field', true );
			echo $someField;
		} //end of foreach
	} //endif ! empty ( $related )
?>

以上是关于text PODS从关系字段中获取值的主要内容,如果未能解决你的问题,请参考以下文章