Excerpts · Custom Field insertions incl. w. shortcodes and from remote posts

$ query = new WP_Query( array( 'p' => XXXXX ) );
$ query->the_post();
The magic Code/Shortcode [ xyz-ics snippet="id"], although invisible, will force the values to be retrieved from the designated remote post 


36347% Typography4
Typography samples | 4 [ acf_txt1] Works here!


36347%

Caption: Øsub4

Typography4 samples

Typography samples | 4

[ sc name=”sc_1″] –
 Typography samples | 4    |   typography4 Edit post - id:36347
logo
img
img1
img2
img3

  The images are defined in the page's ACF custom fields | Sourced from: "typography4" | ID: "36347"

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.▷2



Edit sc_1


   Display new |acf_wys1| shortcodes in functions.php   |acf_wys1| wrong image, |acf_excerpt|, |acf_wys2| entangled id's!!
[ acf_wys1] in functions.php 
function wys1_shortcode (){
    global $ post;
    $ acf_wys1 = get_post_meta( $ post->ID, 'acf_wys1', true );
    return $ acf_wys1;
}
add_shortcode( ' acf_wys1', ' wys1_shortcode' ); 

29311% Card5 [ acf_wys1] [ acf_excerpt]

Testing


•••••••
•••••••
[ acf_wys2][ acf_wys2] DISABLED


Careful with
1/ conflict betw. 2 types of shortcodes in Functions.php (Beaver with the variable "featured" and the new one below, added on Sept2)
2/ Issues with sas_spoilers and image in acf_wys4. Had to revert to Su_spoiler

   Code examples  Incl. code to shortcode
NotOK with shortcodes in remote posts ACF
[ acf_wys1] in functions.php 
function wys1_shortcode (){
    global $ post;
    $ acf_wys1 = get_post_meta( $ post->ID, 'acf_wys1', true );
    return $ acf_wys1;
}
add_shortcode( ' acf_wys1', ' wys1_shortcode' ); 

BeaverB [ featured id='...' my_field='acf_...'] in functions.php
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' );

PHP code to get a custom field from a specific post   
‹?php the_field('acf_excerpt', $post_id); ?› 
OK with shortcodes in remote posts ACF
[ Insert-remote-post-ACF-fields-xyz]
< ?php query_posts('showposts=2'); ? > 
< ?php while (have_posts()) : the_post(); ? > 
[ su_spoiler title="   " open="no" style="fancy;" icon="folder-2" anchor_in_url="no"]
< ?php the_id(); ? >
< ?php the_field('acf_excerpt', $post_id); ? >
< ?php endwhile; ? > 

//WP recommend never to use query_posts
// Shortcodes enabled in Custom Fields: functions.php (field by field)
echo do_shortcode(get_post_meta(get_the_ID(), "MyCustomField", true));
//Check > do_action_ref_array( 'pre_get_posts', WP_Query $query )
//Note: a text field is plain text, therefore it can be directly utilized in php, which is what get_field() is for, rather than the_field() that wraps the data into its own echo function so it’s simply do_shortcode( get_field('name') );
of course the best practice in case there’s no data and if there’s extra html around it is to check if it exists first. ACF docs

if ( get_field('name') ) {
	echo do_shortcode( get_field('name') );   }

add_filter(‘acf/format_value/type=text’, ‘do_shortcode’);

Notes
DRAFTS from doc examples TBD? 
get_fields([ $post_id], [ $format_value]);
$post_id (mixed) (Optional) The post ID where the value is saved. Defaults to the current post.
$format_value (bool) (Optional) Whether to apply formatting logic. Defaults to true.

[ xyz-ics snippet="addacf" acf_name"acf_txt1"] ··· [ xyz-ics snippet="addacf" acf_name"acf_txt1"] 
[ xyz-ics snippet='addacf' acf_name'acf_excerpt'] ··· [ xyz-ics snippet="addacf" acf_name"acf_txt1"]

PHP code to get a custom field from a post
function related_post_acf_shortcode( $atts ) {
  // extract attributs
  extract( shortcode_atts( array(
    'field'      => '',
    'related_field' => '',
    'post_id'    => false,
    'format_value'  => true
  ), $atts ) );
  // get unformatted value of post object field
  $related_post_id = get_field($field, $post_id, false);
  // get value from the related post and return int
  $value = get_field( $related_field, $related_post_id, $format_value);
  // array
  if( is_array($value) ) {
    $value = @implode( ', ', $value );
  }
  // return
  return $value;
}
add_shortcode('related_post_acf', 'related_post_acf_shortcode');

/*  shortcode
  [related_post_acf field="post_object_field_name" related_field="field_name_on_other_post"]
*/

Excerpts | Featured | Tests for Beaver Builder PHP, custom shortcode [ featured id=” my_field=”] in functions.php


Test results: the solution works fine for html, but fails on shortcodes contained in the source posts’ fields. Only the “html” is called, NOT the content generated through shortcodes within each origin post.


   Custom BB featured shortcode display |featured id=54313 my_field=featured|
%%%% [ xyz-ics snippet="id" _id="36347"] %%%%
[ featured id='54313' my_field='featured' ]

Illustration: Articles 1 & 2 side by side Why is it OK here, in Excerpts or Front page, and not in /posts/acf-documentation-functions/?
The shortcode inserted into this post calls the ACF fields from posts Article1 & Article2 with the following values. Both show that the versions using shortcodes now pull data from their origin post.

54313% [ “id” _id=”54313″] Article1
[ featured id='54313' my_field='acf_excerpt' ] 
Using HTML only: Shows the expected result

Article1   id=54313

In this “all HTML” version, using no shortcodes, the title, text, id, image, are direct-coded in the field “ACF_Excerpt” within the post Article1. They all display correctly.

Using shortcodes: Shows error cases when applicable

Article1

  id= 54313  (via wpbb post:id, not acf_id)

(acf_img1)
Article11 id=54313 | Øsub0

Article1 | acf_wys2 metafield. Using meta field called in local shortcode | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

54313
xyz-ihs snippet=Cardframework1

 

50955% [ “id” _id=”50955″] Article2
 | [ featured id='50955' my_field='featured' ] 


EXCERPTS FROM OTHER POSTS USING CONTENT VIEWS PRO | Displays ACF_excerpts field from Posts (eg Article1, Article2 etc.) via the Content View Pro plugin
Note: Advanced Custom Fields (ACF) are now displayed correctly when a filter is applied thanks to this .JS snippet in CV settings


CONTENT VIEWS “PINTEREST” GRID | With filters (Limit 12)
[ pt_view id=”9dcf61fmzf”] REACTIVATE THIS ONE


[ pt_view id=”a0f856e60p”]
[ pt_view id=”cb2a9144sz”]

·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•··•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•··•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·•·

BOTTOM PAGE SECTION

FLEX: √clearfix √box20-20-20-20-20
Q0

▷Q1
ow3-card-float ow3-container
Q2

Q3

Q4