I am in the single-product.php loop and the product has a relationship to an artist post type to which I have the id off the artist.

I need to get the_title() from my custom artist post type while in the single-product.php loop.

My code is getting the title of the product rather than the artist. My code is below. Can anyone please help?

    $artistId = get_field('artist');

    $postId = get_post($artistId);
    if ( $postId ):
        <span id="chty_17">
            <dt><?php the_title(); ?></dt>

1 Answer 1


You can pass a post ID to get_the_title(). So instead of using the_title() to display it, fetch it first like this.

$artist_title = get_the_title( $artistID );
echo $artist_title;

You could do that in one line of course but you might need it somewhere else, too.

  • Great thank you! Will make sure I remember that in future! Commented Sep 15, 2016 at 16:27
  • Happy to help and glad it worked for you.
    – jdm2112
    Commented Sep 16, 2016 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.