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?
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.
This code` <?php
$posts = get_field(‘related_series’, $taxonomy . ‘_’ . $term_id);
if( $posts ): ?>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<a href=”<?php echo get_permalink( $p->ID ); ?>”><?php echo get_the_title( $p->ID ); ?><?php the_post_thumbnail( ‘featured’ ); ?></a>
<?php endforeach; ?>
<?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
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.'">';?></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 !!
The topic ‘Post Object within taxonomy.’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!