Hi i have a repeater field with relationship in it and i want to query all post which are connected from those relationship sub fields to current post. I’ve been going through documentation and forum but i can’t get it working.
Code with which i ended up for now:
function my_posts_where( $where ) {
$where = str_replace( "meta_key = 'wystawcy_$", "meta_key LIKE 'wystawcy_%", $where );
return $where;
}
add_filter( 'posts_where', 'my_posts_where' );
$doctors = get_posts( array(
'numberposts' => -1,
'post_type' => 'any',
'meta_query' => array(
array(
'key' => 'wystawcy_$_kategoria_wystawcy',
'value' => '"' . get_the_ID() . '"',
'compare' => '=',
)
)
) );
print_r( $doctors );
if ( $doctors ):
foreach ( $doctors as $doctor ):
echo get_the_title( $doctor->ID );
endforeach;
endif;
wystawcy – is a repeater field
kategoria_wystawcy – is a relationship field
'meta_query' => array(
array(
'key' => 'wystawcy_$_kategoria_wystawcy',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE',
)
I’ve tried with LIKE but results is same, an empty array 🙁
I could be missing it, but I don’t see anything else wrong with your query.