Support

Account

Home Forums ACF PRO Relationship from a custom post types

Solving

Relationship from a custom post types

  • Hello,
    I have implemented the field relationship to post post and custom post on the home.
    I have a problem with the image of the custom post.
    I would like to take the Image field I entered into the custom management of the custom post I created.
    I attach screenshots and part of code hoping that the request is clear.

    //single-wine-page:
    
    <?php
      $image = get_field('copertina_libro');
      $correlata = get_field('copertina_libro_correlata');
      $size = 'thumbs-liste'; // (utilizzo la mia dimensione personalizzata)
      $sizefull = 'full'; // (utilizzo la dimensione originale)
      ?>
    
      <div class="row">
        <div class="col-md-6">
    
          <div class="img-container">
            <a href="<?php the_permalink() ?>" title="<?php the_title_attribute() ?>"><img class="img-responsive" src=<?php echo wp_get_attachment_image( $image, $sizefull );?></a>
          </div>
    .....
    
    //homepage
    
    <?php
    
    $posts = get_field('correlati_vini');
    $image = get_field('copertina_libro');
    $correlata = get_field('copertina_libro_correlata');
    $size = 'thumbs-liste'; // (utilizzo la mia dimensione personalizzata)
    $sizefull = 'full'; // (utilizzo la dimensione originale)
    
    if( $posts ): ?>
    <div class="wine-list">
     <div class="row row-news ">
     <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>
        <div class="col-md-4">
            <div class="featured-image">
              <a href="<?php the_permalink() ?>" title="<?php the_title_attribute() ?>"><img class="img-responsive" src=<?php echo  wp_get_attachment_image( $image, $size );?></a>
            </div>
    .....
    
  • if you’re trying to get the images from the related posts then you need to get those fields inside of the loop for those posts

    
    //homepage
    
    <?php
    
    $posts = get_field('correlati_vini');
    
    if( $posts ): ?>
    <div class="wine-list">
     <div class="row row-news ">
     <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
        <?php 
          setup_postdata($post);
          
          $image = get_field('copertina_libro');
          $correlata = get_field('copertina_libro_correlata');
          $size = 'thumbs-liste'; // (utilizzo la mia dimensione personalizzata)
          $sizefull = 'full'; // (utilizzo la dimensione originale)
        ?>
        <div class="col-md-4">
            <div class="featured-image">
              <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><img class="img-responsive" src="<?php echo wp_get_attachment_image( $image, $size ); ?>" /></a>
            </div>
    .....
    
  • Thanks, problem solved!

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

The topic ‘Relationship from a custom post types’ is closed to new replies.