I am struggling to output other posts, within the same post type based on whether they have the same relationship field selected, and wondered if you would be able to help please?
I have two custom post types ‘sessions’ and ‘projects’. Each session post has an ACF relationship field to which project it is connected to (Limited to 1). I would like to output other ‘sessions’ on the single-sessions.php tempalte with the same relationship to projects selected. The relationship acf field on a session is called select_project_if_this_is_related
i.e 3x sessions all have the selection of the same ‘project’. I have tried to use the doctors/locations example https://www.advancedcustomfields.com/resources/querying-relationship-fields/ but I can’t get it to output anything with the code I am using.
$sessions = get_posts(array(
‘post_type’ => ‘sessions’,
‘meta_query’ => array(
‘key’ => ‘select_project_if_this_is_related’, // name of custom field
‘value’ => ‘”‘ . get_the_ID() . ‘”‘, // matches exactly “123”, not just 123. This prevents a match for “1234”
‘compare’ => ‘LIKE’
<?php if( $sessions ): ?>