Home › Forums › Front-end Issues › Query to display all posts with ACF relationship value › Reply To: Query to display all posts with ACF relationship value
Hi!
First off, move wp_reset_postdata(); right under the endforeach; in your related posts loop.. that should fix the error with the incorrect ID.
Secondly.. there doesn’t seem to be a default archive link for posts if you don’t include a date or category tag (like http://www.demo.com/2012/). I honestly cant think of a smooth way to solve this the way it’s set up at the moment.. If I where you I’d either rethink it all or id create categories thats named the same as the companies but with a permalink of something like companyname-cat and assign the posts to them as well. That way you could just put this for the readmore link:
<?php
$cat = get_category_by_slug($post->slug.'-cat');
$catlink = get_category_link($cat->term_id);
?>
<a href="<?php echo $catlink; ?>">View all</a>
then you can check in archive.php if it’s trying to display a category with
if(is_cat()){
//the archive is displaying posts from a category
}
If this solution doesn’t work you could create a custom taxonomy and assign it to the posts (besides categories and tags) and use them instead and change the functions accordingly..
<?php
$cat = get_term_by('slug, '$post->slug.'-cat', 'your-taxonomy-slugname');
$catlink = get_category_link($cat->term_id);
?>
<a href="<?php echo $catlink; ?>">View all</a>
and:
if(is_tax()){
//the archive is displaying a term from a taxoonomy
}
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.