根据另一个转发器值获取高级自定义字段转发器字段值 [英] Get advanced custom fields repeater field value based off of another repeater value

查看:71
本文介绍了根据另一个转发器值获取高级自定义字段转发器字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有一个转发器字段,在该字段中,我有一个发布对象字段和一些文本字段。发布对象字段仅获取您设置的任何发布的ID。

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.

当我是一个帖子时,我想运行一个数据库查询,该查询使用当前的帖子ID查找匹配的子字段,然后在同一转发器中获取另一个子字段领域。

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.

任何人都可以帮忙吗?

这是我到目前为止所不需要的,但是我不需要

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


推荐答案

那行不通,我丢了一个几个小时。 ACF转发器字段会获得一个与父帖子ID不对应的新ID(第一个ID除外)。使这一点更加令人困惑:如果删除一个转发器字段,它可以保留在数据库中;因此任何查询都将返回所有转发器字段数据,旧&新。

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.

这篇关于根据另一个转发器值获取高级自定义字段转发器字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆