Support

Account

Home Forums Add-ons Repeater Field Repeater subfield meta query (event, multiple start stop times) Reply To: Repeater subfield meta query (event, multiple start stop times)

  • Hello Jusseb,
    No solution yet, but a nasty workaround, a large query.
    If somebody knows how to make the numbers generic we would have the solution 😉

    Here is my nasty, way too long query:

    $querystr = ”
    SELECT DISTINCT wposts.*
    FROM $wpdb->posts wposts
    LEFT JOIN $wpdb->postmeta wpm1 ON (wposts.ID = wpm1.post_id
    AND wpm1.meta_key = ‘tijdblok_0_start_tijd’)
    LEFT JOIN $wpdb->postmeta wpm2 ON (wposts.ID = wpm2.post_id
    AND wpm2.meta_key = ‘tijdblok_0_eind_tijd’)
    LEFT JOIN $wpdb->postmeta wpm3 ON (wposts.ID = wpm3.post_id
    AND wpm3.meta_key = ‘tijdblok_1_start_tijd’)
    LEFT JOIN $wpdb->postmeta wpm4 ON (wposts.ID = wpm4.post_id
    AND wpm4.meta_key = ‘tijdblok_1_eind_tijd’)
    LEFT JOIN $wpdb->postmeta wpm5 ON (wposts.ID = wpm5.post_id
    AND wpm5.meta_key = ‘tijdblok_2_start_tijd’)
    LEFT JOIN $wpdb->postmeta wpm6 ON (wposts.ID = wpm6.post_id
    AND wpm6.meta_key = ‘tijdblok_2_eind_tijd’)
    LEFT JOIN $wpdb->postmeta wpm7 ON (wposts.ID = wpm7.post_id
    AND wpm7.meta_key = ‘tijdblok_3_start_tijd’)
    LEFT JOIN $wpdb->postmeta wpm8 ON (wposts.ID = wpm8.post_id
    AND wpm8.meta_key = ‘tijdblok_3_eind_tijd’)
    LEFT JOIN $wpdb->postmeta wpm9 ON (wposts.ID = wpm9.post_id
    AND wpm9.meta_key = ‘tijdblok_4_start_tijd’)
    LEFT JOIN $wpdb->postmeta wpm10 ON (wposts.ID = wpm10.post_id
    AND wpm10.meta_key = ‘tijdblok_4_eind_tijd’)
    LEFT JOIN $wpdb->postmeta wpm11 ON (wposts.ID = wpm11.post_id
    AND wpm11.meta_key = ‘tijdblok_5_start_tijd’)
    LEFT JOIN $wpdb->postmeta wpm12 ON (wposts.ID = wpm12.post_id
    AND wpm12.meta_key = ‘tijdblok_6_eind_tijd’)
    WHERE (
    (wpm1.meta_value <= $hour) AND (wpm2.meta_value > $hour)
    OR
    (wpm3.meta_value <= $hour) AND (wpm4.meta_value > $hour)
    OR
    (wpm5.meta_value <= $hour) AND (wpm6.meta_value > $hour)
    OR
    (wpm7.meta_value <= $hour) AND (wpm8.meta_value > $hour)
    OR
    (wpm9.meta_value <= $hour) AND (wpm10.meta_value > $hour)
    OR
    (wpm11.meta_value <= $hour) AND (wpm12.meta_value > $hour)
    )
    AND wposts.post_type = ‘programma’
    AND wposts.post_status = ‘publish’
    ORDER BY wpm1.meta_value ASC
    “;