【问题标题】:Custom field value on a Wordpress multisiteWordpress 多站点上的自定义字段值
【发布时间】:2017-02-13 13:59:19
【问题描述】:

我想从多站点的每个博客中获取自定义帖子类型“团队”的内容。 我设法获得了帖子标题和缩略图,但我无法获得使用 acf 制作的自定义字段的值。我只在当前博客上获得自定义字段的值。 这是我现在拥有的代码:

                global $switched;
                $sites = wp_get_sites();

                foreach ( $sites as $site ) : setup_postdata($post); 
                    switch_to_blog( $site[ 'blog_id' ] );
                    $args = array(
                'posts_per_page' => -1, 
                'post_type' => 'team'
                );

                query_posts($args);
                if (have_posts()) : while (have_posts()) : the_post(); ?>
                 <?php  
                $post_id = get_the_ID();
                 ?>
                    <li class="col-xs-12 col-sm-4 col-md-3">
                        <div class="round-clip">
                            <img src="<?php the_post_thumbnail_url('full'); ?>" alt="team">
                        </div>
                        <div class="colleague-details">
                            <span><?php the_title(); ?></span>
                            <p><?php echo get_post_meta($post_id, 'member_title', true); ?></p>
                            <p><?php the_field('member_phone_number'); ?></p>
                            <a href="mailto:<?php the_field('member_email'); ?>"><?php the_field('member_email'); ?></a>
                        </div>
                    </li>

                <?php endwhile; endif; wp_reset_query();
                switch_to_blog( $current_site );
                $GLOBALS['_wp_switched_stack'] = array();
                $GLOBALS['switched']           = FALSE; 
                endforeach ; 
                ?>

谢谢!

【问题讨论】:

  • 忘了说我使用了get_post_meta,还有the_field...两者都只适用于当前的博客。
  • 对于任何寻找这个的人:上面的代码是正确的,只是其他博客上的字段名称略有不同。只要字段名称相同,上面的代码就可以了

标签: php wordpress advanced-custom-fields multisite


【解决方案1】:

我会试试这个,因为你已经有了 id,

`<?php the_field('member_phone_number', $post_id); ?>`

但不确定它是否会起作用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多