Saturday, July 10, 2021

WP - POD - Custom Taxonomy or Post Type - relationship field

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 );

    }


See the value of variable in WordPress - vardump

 In WP happens that you got to some object and you want to find as much as possible about that object.

So the question is: what is the content of WP object.

Trick which works very often is to use function var_dump($variable)