Home Forums Front-end Issues Nesting relationship querys Reply To: Nesting relationship querys

  • Hi @nathanrobjohn

    I think my previous comment didn’t post! Sorry about that.

    Your query is nearly there. Just check out this doc:

    You need to make a few modifications to add the LIKE query work. Also, updating to ACF 4.3.0 will ensure that the data is saved in this LIKE friendly format (it is possible that 4.2.2 did not)

    Basically, within your loop foreach speaker, you can perform your get_posts query asking for all videos which have selected the current speaker ID and the event ID.
    Your code already shows you have figured out this logic.

    Something that I can see causing an issue is the setup_postdata function. This is a great function for a single loop, however once you proceed into the nested loop (video), this function will cause all sorts of issues. Basically, it will kill the speakers loop completely!

    I would instead, not use the setup_postdata function, but just pass the current ID into all the WP functions. Also, you will need to change your loop to not use the $post variable, instead use $speaker or $event. You can get a title like so:

    echo get_the_title( $speaker->ID );

    Hope that helps.