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 Nataliette (cool name)
You can limit the number of posts by adding ‘posts_per_page’ => 5
to the query. Change 5 to whatever number you want.
As for setting a view more link that’s a bit more complicated since there’s no default archive for posts queried by meta value. I suppose you could do something like this:
<?php
$company_ID = $post->ID; //get the id of the current company
$archive = get_post_type_archive_link('post').'?company='.$company_ID;
?>
<a href="<?php echo $archive; ?>">Read more</a>
This would mean that when you click the read more you get sent to the regular post archive but with an GET parameter.. Then on archive.php you can do a check for this parameter and if it’s present query all posts with that meta value.
if(isset($_GET['company'])){
}
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!
ACF PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp
— Advanced Custom Fields (@wp_acf) January 24, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.