Support

Account

Home Forums ACF PRO Post Object within taxonomy.

Solved

Post Object within taxonomy.

  • Hello, I have worked hard on taxonom-slug. This time I’m having a problem I’m not able to make the repeater field work in conjunction with object relationship. I already added the code and it does not work. It looks like the_sub_field can not work.
    What would be the best way to display the field related to the main image of the post type and the titlei within the taxonomy page?

  • Please share your code otherwise it’s a guessing game…

  • What I am currently needing is to make inside the tag the related post separated by divs. Example: Movies | Series | News. Currently it all comes together. Using acf I can make the related post appear, however the post image does not appear just the title in the custom field.

  • Can you please share what you have so far ?

  • This code` <?php

    $posts = get_field(‘related_series’, $taxonomy . ‘_’ . $term_id);

    if( $posts ): ?>
    <ul>
    <?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
    <li>
    <a href=”<?php echo get_permalink( $p->ID ); ?>”><?php echo get_the_title( $p->ID ); ?><?php the_post_thumbnail( ‘featured’ ); ?></a>

    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>`

    I used the example link: https://www.advancedcustomfields.com/resources/relationship/
    And I added to get the featured image from the related post. However, he repeats the same image for all posts. This is not a repeater field. I’m doing the test without the repeater field.

  • I would use this code to retrieve the image.

    $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $p->ID ), 'image-size', false, '' );

    This way you pass the correct post ID to retrieve the featured image from.

    Then to get the file location, you echo $feat_image[0].

  • It worked like a charm, I only have one problem the image inside the link it stays as if it was redirection will be that I did something wrong example:
    https://www.site.example/person/charlie-cox/%E2%80%9Dhttps://www.site.example/series/daredevil/%E2%80%9D

  • It seems you have incorrect characters in your link. Fix those.

    %E2 = â
    %80 = `
    %9D = space

  • I was able to solve it, thank you one more time.

      I now have to check how the code does not influence the tags. When I link it it also changes the tags in the loop. I’ll check that out.
    For those who have doubts about how to proceed, follow the code below:

    <?php
    
    $posts = get_field('related_series', $taxonomy . '_' . $term_id);
    
    if( $posts ): ?>
    <ul>
    <?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
    <li><?php $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $p->ID ), 'featured', false, '' );?>
    <a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?><?php echo '<img src="'.$feat_image[0].'">';?></a>
    
    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    Then just code for your needs. I’ll try to do per repeater field.

    I only need to solve three issues with acf to be able to finish my project =). Man, I’ll come soon, pay for some coffee or juice for you!
    Beee helping ever !!

  • This code seems ok… should work imo.

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

You must be logged in to reply to this topic.