I think I found the issue. It seems ‘post_where’ filter won’t work with
get_posts() function. To fix it, you need to set
suppress_filters option to
false. Please take a look at the note on this page: https://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where.
So, your code should be something like this:
$formations = get_posts(array( 'suppress_filters' => FALSE, 'post_type' => 'formation', 'meta_query' => array( array( 'key' => 'chapitres_%_lecon', // name of custom field 'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234" 'compare' => 'LIKE' ) ) )); if( $formations ): ?> . . .
I hope this helps 🙂
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!