Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://github.com/tmconnect/acf-relationship-multisite
- Download filenya di filefactori
- Cara menampilkan di frontend:
- Jika ambil data model Post ID (ganti field_name dengan nama fieldnya, spt resensi)
- <?php
- // get field value
- $posts = get_field('field_name');
- if( $posts ):
- // switch to multisite
- switch_to_blog( $posts['site_id'] ); ?>
- <ul>
- <?php foreach ($posts['selected_posts'] as $post): // variable must be called $post (IMPORTANT) ?>
- <?php setup_postdata($post); ?>
- <li>
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
- <span>Custom field from $post: <?php the_field('author'); ?></span>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
- <?php restore_current_blog(); // IMPORTANT switch back to current site?>
- <?php endif; ?>
- Jika ambil datanya model Post Object
- <?php
- // get field value
- $posts = get_field('field_name');
- if( $posts ):
- // switch to multisite
- switch_to_blog( $posts['site_id'] ); ?>
- <ul>
- <?php foreach ($posts['selected_posts'] as $acf_post): ?>
- <li>
- <a href="<?php echo $acf_post->guid; ?>"><?php echo $acf_post->post_title; ?></a>
- <span>Custom field from $post: <?php the_field('author', $acf_post->ID); ?></span>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php restore_current_blog(); // IMPORTANT switch back to current site?>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement