Get advanced custom fields repeater field value based off of another repeater value

怎甘沉沦 提交于 2019-12-23 01:13:45

问题


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.'%'
)
);

回答1:


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.



来源:https://stackoverflow.com/questions/27980496/get-advanced-custom-fields-repeater-field-value-based-off-of-another-repeater-va

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!