Support

Account

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