Home › Forums › Front-end Issues › Limit relationship posts per page › Reply To: Limit relationship posts per page
Hi @blg002
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.
Thanks
E
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.