I've been using custom posts on my website, among them there are : "session" and "lecture".

The custom post "lecture" has many custom fields such "title", "duration"...

The custom post "session" has many custom fields too, one of them is "session_lecture" that points to a lecture : hence, a session is linked to a lecture. The lecture is chosen in a dropdown menu, generated with a nice tool : cmb2 metaboxes.

I handle the display of a session and a lecture with filters, like :


Those filters retrieve the custom fields and display them the way I want.

I'd like, for each lecture, to display a list of sessions that provide this lecture. So, within the filter above, I have written :

$args = array(

            'post_type' => 'session',
            'meta_key'     => 'session_lecture',
            'meta_value'   => '$id', //$id is the id of the current lecture
            'meta_compare' => '=',

            $query = new WP_Query( $args ); 

            while ($query->have_posts()) : $query->the_post();

But the query seems to return nothing. What's wrong with my query ? Should I use another mechanism ? Thanks

1 Answer 1


Solved, I removed : 'meta_compare' => '=' !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.