Title: Query related custom post type
Last modified: November 29, 2023

---

# Query related custom post type

 *  [dba1999](https://wordpress.org/support/users/dba1999/)
 * (@dba1999)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-related-custom-post-type/)
 * Dear sir’s, I’m developing plugin with multiple custom post types where relationships
   between them are done through storing id’s of the other as meta fields;
   event
   custom post typeinstructor custom post typeattendee custom post type
 * attendee stores the meta ‘event-id’, while event stores the meta ‘instructor-
   id’
 * What I’m trying to express a join query that will filter the admin table for 
   attendee based on instructor-id.
 * I’m triggering my ‘pre_get_posts’ filter function but I don’t know how to best
   build my $query->get(‘meta_query’) when $_GET[‘instructor-id’] is set.
 * Any help to get on how to set my ‘meta_query’ so I can filter based on instructor?

Viewing 1 replies (of 1 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-related-custom-post-type/#post-17240173)
 * This sould match your question:
 *     ```wp-block-code
       function custom_post_filter( WP_Query $query ): void {
           if ( is_admin() && $query->is_main_query() && !empty($_GET['instructor-id']) ) {
               $query->set(
                   'meta_query',
                   array(
                       array(
                           'key' => 'instructor-id',
                           'value' => absint($_GET['instructor-id']),
                           'compare' => '='
                       ),
                   )
               );
           }
       }
       add_action( 'pre_get_posts', 'custom_post_filter' );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Query related custom post type’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [threadi](https://wordpress.org/support/users/threadi/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/query-related-custom-post-type/#post-17240173)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
