Support

Account

Home Forums Front-end Issues Relationship field – slug only?

Solved

Relationship field – slug only?

  • I am using the Relationship field to show a list of links. Is it possible to get just the slug and not the full permalink? This was the code I used:

     <?php while(has_sub_field('event_details')): ?>                                            
          <h3><?php the_sub_field('event_name'); ?></h3>
          <?php $links = get_sub_field('session_links');
           if( $links ):  foreach( $links as $link ): ?>
    	   <a href="<?php echo get_permalink( $link->ID ); ?>"><?php echo get_the_title( $link->ID ); ?></a>
            <?php endforeach; endif; endwhile ?>

    I appreciate any direction. Thank you.

  • I solved it. I just needed to use this:

    echo( basename(get_permalink()) );
    
    

    instead of get_permalink().

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.