Issues with insertion of ACF fields sourced from other posts into this page

1
DOCUMENTING THE ISSUE: This page highlights the desired workflow and the cases in which ACF fields containing shortcodes do not process the proper ACF field values.
THE SEARCH FOR A SOLUTION: Identification of two post grid plugins, where a solution to the processing issue might be found. Identification of code snippets.

Objective: The objective is to source select ACF fields including texts, images etc. from other posts such as Articles (the source posts) and to insert them into this Front page (the destination page), in order to tease viewers to go and read the full article.
Problem: The problem is that in most cases SHORTCODES contained within ACF custom fields in the post/Articles are NOT executed remotely. They get mixed up when they reach this Front page and process values from the equivalent custom fields present here.

1. Hidden content (portion of page)

Protected Area

This content is password-protected. Please verify with a password to unlock the content.

Workflow: The ‘featured’ article ACF field is targeted using the following shortcodes:

 [ featured id='123' my_field='featured'] 

or

 [ acf field='acf_excerpt' post_id='123'] 

(See more details below). They allow to select the specific post and the specific custom field from that post. The ‘featured’ field is then inserted into the Front page. The field itself contains several references to other ACF fields within the source post (Images, texts, links etc.)


The issues arise when the ACF content is called from the fields in the Front page, instead of content from the articles.

2
Inserting the fields from remote posts: The ACF fields below are inserted using the “featured” shortcode which allows to target a post by id and field name.

   View the PHP code:

The “featured” PHP shortcode is added to the OWP child theme. Go to functions.php

//  Use  filling the '' with the correct values for you
function gg_get_field($attr){
    $args = shortcode_atts( array(     
            'id' => '1',
            'my_field' => 'featured'
        ), $attr );
 
    return get_field($args['my_field'], $args['id']);
}
add_shortcode( 'featured' , 'gg_get_field' );

  Other: FINALLY here is another PHP code to get a custom field from a specific post! |   ‹?php the_field(‘acf_excerpt’, $post_id); ?› |


There are obviously other methods such as the “Insert page” plugin (no field selection) or ACF’s field display methods (that require developer coding skills which we do not have).



3
To help demonstrate the issue, the text and image ACF field values contained in this Front page’s own “featured” field are inserted here before the article inserts:

Source=   id= [ wpbb post:id]

The ACF content and values for this page’s “featured” are purposely highlighted to demonstrate how they may show up by error in the tests. They should NOT show up in the Article inserts below. The issues arise only when the source posts’ ACF fields contain shortcodes. Instead of picking up values from the Article, they pick up the content from the Front page fields.


ID=% | R-@-> | ID=%
4

Article1 | id= 54313:   The field “featured” contains both Htmland Shortcodes,



ID=% | R-@-> | ID=%
5

Article2 | id= 50955:   The field “featured” contains both Htmland Shortcodes,


ID=% | R-@-> | ID=%
6
Sample inserts from remote Posts | Resets and new id’s introduced when required to target ACF/shortcodes.

∫ Article 7 | SC1


     |    Edit post – id:

logo
img
img1
img2
img3

  The images are defined in the page’s ACF custom fields | Sourced from: “” | ID: “”


Edit sc_1
Popup sc_1

% Shortcode sc_1

∫ Article 7 | SC2


     |    Edit post – id:

acf_wys4

Edit sc_2
|   Popup sc_2

% Shortcode sc_2

∫ 35406 Card0 | SC2


     |    Edit post – id:

acf_wys4

Edit sc_2
|   Popup sc_2

% Shortcode sc_2

∫ 50966 Article 3 | Featured

|
 

acf_wys2
acf_wys3

Edit CF5-LGC
|   Popup CF5-LGC id=52963


     |    Edit post – id:

logo
img
img1
img2
img3

  The images are defined in the page’s ACF custom fields | Sourced from: “” | ID: “”


Edit sc_1
Popup sc_1
|
acf_wys2
acf_wys1
acf_wys5

Edit CF2-LGC
|   Popup CF2-LGC id=52960


% Featured

8
Conclusion: After extensive research the issue has been resolved. At the outset, the shortcodes were correctly identified inside the fields of their source posts, but they ended up processing the values from THIS destination page and its custom fields, NOT the ones from the source posts. The new code now forces the data and values to be sourced from the origin posts.



Exceptions! There was another solution to this issue. Grid based lay out solutions such as Content Views or Beaver Builder “insert Posts” handle multiple posts in bulk and seem to perform the remote shortcode execution and rendering properly. See the expected result in this page /grid-based-acf-post-inserts. The grid solutions manage to pre-process the shortcodes in the source posts. The challenge was to identify how to make the solution consistent and pervasive across all types of inserts.