Support

Account

Forum Replies Created

  • cinq75,

    Have a look at my post about $wpdb. This might help you as well. Do something like this:

    First, get all post ids of bands for a particular venue id, like:

    global $wpdb;
    $bands = $wpdb->get_results( "SELECT * FROM wp_postmeta WHERE meta_key LIKE 'venuerepeaterfieldname_%_band' AND meta_value = '{$venue_id}'", OBJECT );

    The $bands object will contain the band post ids and also the row number which is the order in which it lies in the repeater field . The repeater row index is important information because you can use that to get all other fields in the same row of that repeater field.

    For example, if you band added to the venue as the 3rd row of the repeater field, you will have that information in the $bands object array as “venuerepeaterfieldname_3_band”. You can then do something like:

    $band_index_array = explode("_","venuerepeaterfieldname_3_band");
    $band_index = $row_index_array[1]; //equal to 3

    Then simply get all the values on that repeater row, using:

    $bands = get_field('venuerepeaterfieldname', $venue_id);
    $concerned_band = $bands[$band_index];

    $concerned_band array will contain all fields that you may need. Hope that helps.

  • Ok,

    I was able to find a solution. Its what Elliot has suggested but using $wpdb. For some reason, Elliot’s meta query example did not work for me (returns no results).

    Here is what I did:

    global $wpdb;
    $meetings = $wpdb->get_results( "SELECT post_id FROM wp_postmeta WHERE meta_key LIKE 'members_%_staff' AND meta_value = '{$user_id}'", OBJECT );

    In the above example:

    • “members” is the name of the repeater field
    • “staff” is the name of the subfield (a user in my case)
    • “{$user_id}” is the ID of the user which we need to lookup in meetings

    $meetings contains all the post ids that have the staff (user) added as a subfield.

    Like Elliot mentioned, the “%” is important as we don’t know the row index of the subfield.

    $wpdb packs so much power than your standard wordpress $args query model. Hope that helps someone 🙂

  • Hi Elliot,

    I am looking to solve a similar problem. However, instead of a post relationship field, I need to look for USERS who were added inside of a repeater field.

    Basically, I have a post type “meeting”. Under each meeting, there is a repeater field “staff members” where I add “users” to a meeting.

    When users log-in, they should be able to see what meetings they have been assigned to. I see that you have used ‘value’ => ‘”‘ . get_the_ID() . ‘”‘. How would we go on about doing the same thing when we are dealing with user relationship field?

    Thanks.

  • Hi,

    I was wondering the same thing and found the answer here: http://wordpress.stackexchange.com/questions/78649/using-meta-query-meta-query-with-a-search-query-s

    It has a few extra steps but gets the job done.

    Also, I noticed a little hiccup in my case. When the search was supposed to return nothing, it returned all posts. I solved the problem by wrapping the loop between an IF statement, like:

    if(!empty($unique)) {
    //wp_query here
    }

    For some reason, wp_query was returning all posts when post__in was an empty array.

    Hope that helps!

Viewing 5 posts - 1 through 5 (of 5 total)