1

We have 3 custom post types and we need to query all 3 and join them in order the get that data to build up a complete list of films at a venue.

Tables are as follows, with there unique ID's. The unique ID's are stored inside a custom field.

  1. Cinema Venues (venues) - venueID
  2. Cinema Events (events) - venueID & filmID
  3. Cinema Films (films) - filmID

NB: Cinema Events contains all the pricing information + times for each film.

How can I join these with a statement to obtain all events + films at a venue?

With a query simalar to this.

$filmsAtCinema = get_posts(array(
                        'post_type' => array('venues','events','films')  
                        'meta_query' => array(
                            'relation' => 'and',
                            array(
                                'key' => 'venues',
                                'value' => 'venueID', 
                                'compare' => 'LIKE'
                            ),
                            array(
                                'key' => 'events',
                                'value' => 'venueID', 
                                'compare' => 'LIKE'
                            ),
                            array(
                                'key' => 'films',
                                'value' => 'filmID', // Film ID obtained from Events. 
                                'compare' => 'LIKE'
                            )

                        )
                    ));

Any help is greatly appreciated. Thanks!

  • How does the final output look like? – Tung Du Sep 28 '18 at 10:02
  • Don't have a final output as yet, I haven't created the appropriate query to get an output. Normally i might run a SQL query with a LEFT JOIN command. – Ian Bryce Sep 30 '18 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.