• Hi Phi, First – thank you for your work on this very helpful plugin. I am using ACF with a hybrid theme (_S) – I have a custom post type for “seminar” that has a relationship with another custom post type for “team members”. This allows me to include the featured image and excerpt from the “team post”. I am not sure how to include the featured image from the team member post within a query loop for “seminar” using your plugin – but it seems like it could be possible? I am using the a /parts/ folder to allow me to visually edit the archive-seminar part… Any help you can provide is appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Phi Phan

    (@mr2p)

    Hi Emily @eatpaintchic,

    You can display anything with this block with custom code. Here is the code to display both the featured image and excerpt from the related team member inside a seminar query loop:

    add_filter( 'meta_field_block_get_acf_field', function ( $block_content, $post_id, $field, $raw_value ) {
      $field_name = $field['name'] ?? '';
    
      // Replace team_member_image with your unique name.
      if ( 'team_member_image' === $field_name ) {
        // Get post id for team member post.
        $team_member_id = get_field( 'team_member', $post_id );
    
        // Has a value.
        if ( $team_member_id ) {
          $block_content = get_the_post_thumbnail( $team_member_id );
        }
    
      }
    
      return $block_content;
    }, 10, 4);
    
    add_filter( 'meta_field_block_get_acf_field', function ( $block_content, $post_id, $field, $raw_value ) {
      $field_name = $field['name'] ?? '';
    
      // Replace team_member_excerpt with your unique name.
      if ( 'team_member_excerpt' === $field_name ) {
        // Get post id for team member post.
        $team_member_id = get_field( 'team_member', $post_id );
    
        // Has a value.
        if ( $team_member_id ) {
          $block_content = get_the_excerpt( $team_member_id );
        }
      }
    
      return $block_content;
    }, 10, 4);

    In this snippet, I assume that you have an ACF field (Post Object) named team_member in the seminar post to store the related team member. To display the featured image, you should add an instance of MFB and set the field name as team_member_image. To display the excerpt, add another instance with the field name as team_member_excerpt. Set the meta type for both instances as meta. You don’t have to create a custom field for two fields team_member_image and team_member_excerpt. They are like dynamic fields created at runtime.

    I’ve not tested it myself, but I believe it should work. Please let me know if it’s working and feel free to discuss if you need further help.

    Regards, Phi.

    Plugin Author Phi Phan

    (@mr2p)

    Ah, you have to set the field type as acf not meta for my custom code.

    Phi.

    Thread Starter Emily Rapport

    (@eatpaintchic)

    Thank you Phi! So – I’m not sure where to put this code. Should I be adding to a functions.php file or does this need to be in my archive-team_member.php? And, I did not use the Post Object field – I used the “relational” field although it appears to output the same type thing (?) – but I can change this if you recommend it. I appreciate your help!

    Plugin Author Phi Phan

    (@mr2p)

    @eatpaintchic You can put this code in the functions.php file. You can use any kind of field as long as it stores a post id of member post type.

    Plugin Author Phi Phan

    (@mr2p)

    Hi @eatpaintchic, Any update on this? If you need further help, please feel free to discuss more.

    Phi.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Possible to get relational ACF fields?’ is closed to new replies.