If you are wondering how to traverse relationship field of custom post type or custom taxonomy created using PODs here is some code which can help you.
This code is running on the archive page. Archive is custom taxonomy created with PODS. Name of the relationship field is child_category.
Note that this is not copy/paste code. Its just code which works but you need to change it according to your configuration.
$current_term = get_queried_object();
//echo $current_term->term_id;
$pod = pods( 'gif_category', $current_term->term_id );
$related = $pod->field( 'child_category' );
if( !empty($related)){
//var_dump( $related );
foreach ( $related as $rel ) {
//echo "<br/>aaaaaaaaaaa";
//echo $rel['slug'];
$slug = $rel['slug'];
//echo $slug;
//echo get_term_link( $slug, 'gif_category' );
//echo "<br/>";
echo "<a href='" . get_term_link( $slug, 'gif_category' ). "'>".$rel['name']."</a>";
echo ", ";
//var_dump( $rel );
//echo get_permalink( $id );
}
}
No comments:
Post a Comment