• Resolved junkes

    (@junkes)


    Hey,

    I have a CPT created with Pods called Song and another one called CD. Some songs are attached to more than one CD. Is it possible to set a “main” CD that I could use, for example, in a breadcrumbs or whatever? Just like when you select more than one category in a WordPress post then you can choose the “main” one.

    If that’s not possible, is there some alternative? Is there a function or something to attach to a {@CD,some_function} in a pod template to get just that “main” CD?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Paul Clark

    (@pdclark)

    With this PHP function defined in your theme’s functions.php or a plugin:

    function link_to_first_post( $posts ) {
    	if ( empty( $posts ) ) {
    		return '';
    	}
    	ob_start();
    	?>
    	<a href="<?php echo esc_url( get_permalink( $posts[0]['ID'] ) ); ?>">
    		<?php echo esc_html( get_the_title( $posts[0]['ID'] ) ); ?>
    	</a>
    	<?php
    	return ob_get_clean();
    }

    The shortcode/magic tag would be: [pods]{@cd,link_to_first_post}[/pods]

    • This reply was modified 3 years, 6 months ago by Paul Clark.
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @junkes

    I personally would create an extra field for such a purpose.
    However you could use @pdclark code and set the first relationship as the “main” item.

    Cheers, Jory

    Thread Starter junkes

    (@junkes)

    Hey, @pdclark, that worked as a charm, thank you very much. I wonder if it’s possible to do that not with post_title but another field in CD…

    Plugin Support Paul Clark

    (@pdclark)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘“Main” Item from a Relationship Field’ is closed to new replies.