0

I created through ACF a relationship between blog posts and the custom post type, which contains employee profiles. Through the relationship, I am able to display links to the employee's profile, who is the author of a post.

I want to display now the list of posts created by employees at their profiles. I was able to find a code which does that. Unfortunately, whenever I assign more than 5 blog posts to an employee, the next ones are not visible. Would you be able to help me and tweak the code to display more than 5 posts in new rows?

<div class="author-content">

        <?php 
        /*
         *  Query posts for a relationship value.
         *  This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
         */

         $documents = get_posts(array(
                     'post_type' => 'post',
                     'meta_query' => array(
                      array(
                            'key' => 'our_people_author', // name of custom field
                            'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
                            'compare' => 'LIKE'
                                )
                            )
                        ));

                        ?>
        <?php if( $documents ): ?>

          <ul class="table-author">
             <?php foreach( $documents as $document ): ?>
<li class="singleauth-list">
<a href="<?php echo get_permalink( $document->ID ); ?>"><img src="<?php echo get_the_post_thumbnail_url($document->ID, 'thumbnail');?>" class="people-post-image"></a>
                   <a href="<?php echo get_permalink( $document->ID ); ?>" class="author-links">
                     <?php echo get_the_title( $document->ID ); ?>
                   </a>
</li>
             <?php endforeach; ?>
         </ul>
      <?php endif; ?>
</div>

1 Answer 1

0

Below is the updated code to fetch posts, please check is that helpful:

$documents = get_posts(array(
                         'post_type' => 'post',
                         'posts_per_page' => -1,
                         'meta_query' => array(
                          array(
                                'key' => 'our_people_author', // name of custom field
                                'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
                                'compare' => 'LIKE'
                                    )
                                )
                            ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.