1

I have a repeater field on a page, in that field i have a post object field and a few text fields. The post object field just gets the ID of whatever post you set.

When i am a single post i want to run a database query that uses the current post ID to find the matching sub field, then get another sub field in that same repeater field.

Can anyone help with this?

This is what i have so far which is not want i need but its the closes it have been able to get

$games_id_array = $wpdb->get_results(
$wpdb->prepare( 
    "
        SELECT * 
        FROM wppp_postmeta
        WHERE meta_key LIKE %s
        AND meta_value LIKE %s
    ",
    'contributing_game_creators_%_game_creator_roles',
    '%'.$search_value.'%'
)
);
Zackskeeter
  • 609
  • 2
  • 10
  • 27

1 Answers1

0

That won't work, I've lost a few hours to it. The ACF repeater fields get a new id that doesn't correspond to the parent-post id (except for the first one). To make this even more confusing: If you delete a repeater field, it can stay in the database; so any queries will return all of the repeater-field data, old & new.

The best workaround I've found for this is to loop the repeater field silently and push the data to a multidimensional array. Then loop over that array again to produce the output.

admcfajn
  • 2,013
  • 3
  • 24
  • 32