Home › Forums › Front-end Issues › Limit relationship posts per page › Reply To: Limit relationship posts per page
Normaly, you would use the get_field to return an array of $post object, but it is possible to use the get_field to return only the post ID’s, which you can then use in your WP_Query to perform the limit and orderby params.
<?php // get only first 3 results $ids = get_field('conference_talks', false, false); $query = new WP_Query(array( 'post_type' => 'conferences', 'posts_per_page' => 3, 'post__in' => $ids, 'post_status' => 'any', 'orderby' => 'rand', )); ?>
Note that the get_field function has 2 false parameters. The first param is for the $post_id and is not relevant, but the second one is to tell ACF not to format the value, and return only what is in the DB (array of IDs)
Hope that helps.
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.