Home › Forums › Front-end Issues › Relationship – splitting results by post type › Reply To: Relationship – splitting results by post type
I’ve done this with get_post_type():
<?php
$rel_field_ids = get_field( 'rel_field' );
$rel_field_ids_grouped = array();
foreach ( $rel_field_ids as $rel_field_id )
{
$post_type = get_post_type( $rel_field_id );
$rel_field_ids_grouped[ $post_type ][] = $rel_field_id;
}
ksort( $rel_field_ids_grouped );
print_r( $rel_field_ids_grouped );
?>
Code not tested.
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.