WordPress: How to get ACF field values from another post?
February 22, 2021

Printing array from the current post and page is pretty straight forward. Similarly, printing repeater in the same post or page is relatively simple.

But when it comes to getting ACF fields values from another post, it becomes a bit tricky. Let’s go through some examples.

Printing a field from another post

<?php $other_page = 12; ?>
<p><?php the_field('field_name', $other_page); ?></p>

Saving a field from another post to a variable

$other_page = 12;
$variable = get_field('field_name', $other_page);
//do something with the saved variable

Getting repeater values from another post

For repeater values, the_sub_field and get_sub_field don’t need a post id parameter like the_field and get_field.

if( have_rows('repeater_field_name', $other_page) ):
  while( have_rows('repeater_field_name', $other_page) ): the_row();    
    $sub_field_3 = get_sub_field('sub_field_3');
    //do something with the saved variable

Read more on ACF Docs


Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress? Mar 3 substring() Method in JavaScript Mar 3 Window setInterval() Method in JavaScript Mar 2 How to zoom an element on hover using CSS? Mar 2 the box-sizing property in CSS

You might also like these

Give buttons accessible namesUI/UXHow to add a ribbon on top of a container using CSS?CSSDifferent Types of Functions in JavaScriptJavaScriptWhere is the PHP log file located on Mac OS?PHPLearn how to use Self JOIN in SQL and MySQLSQL/MySQLHow to change perception and behavior of a person for acceptance of new systems?MiscHow to Create a Backup From Any Database in SQL?SQL/MySQLHow to zoom an element on hover using CSS?CSSJavaScript Number MethodsJavaScriptHow to replace HTML lists using CSS Counters?CSSLearn to Implement Estimated Reading Time using PHP Part 2: Final Implementation with Source CodePHPKeyValuePipe in Angular 9Angular