Support

Account

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'])){
    
    }