Support

Account

Home Forums ACF PRO Post Type with Relationship

Helping

Post Type with Relationship

  • Hi,

    I’m trying to get the post type name of posts that are fetched with the relationship field.

    Example:

    $post = get_sub_field('related_post');
     setup_postdata($post);
     $relatedLink =  get_the_permalink();
     $relatedPostType = get_post_type_object( $post );
     $relatedPostTypeName = $relatedPostType->name;
     wp_reset_postdata();

    $relatedLink works fine so I know I’m getting the right post, however I get the following error while trying to display $relatedPostTypeName:

    “Trying to get property of non-object in…”

    The field ‘related_post” is set to be a post object. What am I missing?

    Mattias

  • SOLVED. Of course my own mistake…

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

The topic ‘Post Type with Relationship’ is closed to new replies.