[英]Get field value of sub site in wordpress by ACF
We have a Wordpress
website which has 10 sub sites(blogs) . 我们有一个
Wordpress
网站,其中有10个子站点(博客)。 We show the latest post of those sub sites on the main site . 我们在主站点上显示这些子站点的最新帖子。 Recently we added and use Advanced Custom Field which is active now on the main site and all those 10 sub sites and in each one we sat just a true/false field and its name is :
is_announce
. 最近,我们添加并使用了“ 高级自定义字段” ,该字段现在在主站点和所有这10个子站点上都处于活动状态,并且在每个子站点中,我们只设置了一个true / false字段,其名称为:
is_announce
。 In each site ( main or sub sites ) we have access to that field by get_field
and it works great . 在每个站点(主站点或子站点)中,我们都可以通过
get_field
访问该字段,并且效果很好。 The problem is , on the main site we have no access to those fields of sub sites.It seems get_field
works good just for each site's scope ( main or sub sites ) 问题是,在主站点上,我们无法访问子站点的这些字段。似乎
get_field
仅对每个站点的范围(主站点或子站点)都有效
How can we fix it ? 我们该如何解决?
Addition : As i told you we show the latest post of each sub website . 另外:正如我告诉你的,我们显示每个子网站的最新帖子。 each one has been featured by one custom field (
is_announce
) . 每个字段都有一个自定义字段(
is_announce
)。 We want to read its value and if it is True
, show something on the top of each post , something like tag . 我们想读取它的值,如果它是
True
,则在每个帖子的顶部显示一些内容,例如tag。
Based on RST's comment , i could solve my problem : 根据RST的评论,我可以解决我的问题:
<?php
$slug = $post->blogname;
$blog_id = get_id_from_blogname($slug);
switch_to_blog($blog_id);
if( get_field('is_announce') )
{
echo "<div class='announce-container'>ANNOUNCE</div>";
}
restore_current_blog();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.