Advertisement
pusatdata

ACF Plugin: Another link post from another blog multisite

Oct 13th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. https://github.com/tmconnect/acf-relationship-multisite
  2.  
  3. Download filenya di filefactori
  4.  
  5. Cara menampilkan di frontend:
  6.  
  7. Jika ambil data model Post ID (ganti field_name dengan nama fieldnya, spt resensi)
  8.  
  9. <?php
  10. // get field value
  11. $posts = get_field('field_name');
  12.  
  13. if( $posts ):
  14. // switch to multisite
  15. switch_to_blog( $posts['site_id'] ); ?>
  16. <ul>
  17. <?php foreach ($posts['selected_posts'] as $post): // variable must be called $post (IMPORTANT) ?>
  18. <?php setup_postdata($post); ?>
  19. <li>
  20. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  21. <span>Custom field from $post: <?php the_field('author'); ?></span>
  22. </li>
  23. <?php endforeach; ?>
  24. </ul>
  25. <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
  26. <?php restore_current_blog(); // IMPORTANT switch back to current site?>
  27. <?php endif; ?>
  28.  
  29.  
  30. Jika ambil datanya model Post Object
  31.  
  32. <?php
  33. // get field value
  34. $posts = get_field('field_name');
  35.  
  36. if( $posts ):
  37. // switch to multisite
  38. switch_to_blog( $posts['site_id'] ); ?>
  39. <ul>
  40. <?php foreach ($posts['selected_posts'] as $acf_post): ?>
  41. <li>
  42. <a href="<?php echo $acf_post->guid; ?>"><?php echo $acf_post->post_title; ?></a>
  43. <span>Custom field from $post: <?php the_field('author', $acf_post->ID); ?></span>
  44. </li>
  45. <?php endforeach; ?>
  46. </ul>
  47. <?php restore_current_blog(); // IMPORTANT switch back to current site?>
  48. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement