Support

Account

Home Forums Front-end Issues Two custom WordPress post types and querying with ACF relationship

Solved

Two custom WordPress post types and querying with ACF relationship

  • Hi all

    I have two custom post types, ‘Artist’ and ‘Media’. Various reasons for setting two post types. So currently, I add an image or video by creating a new Media post, I have an ACF relationship (artist) field that allows me to select an Artist. So the result I am trying to get to is for the user to go to /artist/artist-name and have all the media posts for that particular artist display.

    Here are some screenshots of my ACF fields. So the first one is the ACF fields assigned to the Artist post type:

    …which basically allows me to create an artist overview page.

    Then for the Media post type I have this:

    Notice the ‘artist’ relationship field.

    When adding a new media post I have this:

    …whereby, I set the artist that the image/film relates to.

    On the frontend, this is where I am struggling, I have a single-artist.php file and I am scratching my head as to how I can list all media posts for the artist you are viewing?

    I hope somebody can help.

  • I figured it out, this helped: https://www.advancedcustomfields.com/resources/querying-relationship-fields/

    in particular adding ‘$media->ID’ along when calling the custom fields.

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

The topic ‘Two custom WordPress post types and querying with ACF relationship’ is closed to new replies.