Support

Account

Home Forums ACF PRO Echo ShortCode with Post ID

Solving

Echo ShortCode with Post ID

  • Hi, I checked some of keywords to see similar topics but i didn’t find. If any similar topic that you think to move this topic I appreciate.

    Problem:

    I have Cars and parts as post and there is 2 same named ACF field with biderctional. When i add one part as post and assign with ACF to Car, both works and shows.

    I made one shortcode and used in parts

    
    	<?php foreach( $parts as $post ): 
     	// Setup this post for WP functions (variable must be named $post).
            setup_postdata($post); ?>
    <?php $parts= the_field('parts_cars', $post); ?>
    <?php echo $parts; ?>
    
    '23004, 25012' // echo the value comes correctly when i echo $parts;
    
    <?php echo do_shortcode(' [car-parts-1 items_number="" external_link="1" category="" items_id="'.$parts.'" columns="4" order="ASC" orderby="name" title="Compatible Parts"]
    

    It brings emtpy Value on ‘items_id’ When i put $parts inside ‘. .’ ECHO becomes empty without an any error.

    I also post it with non-exist shortcode to post do shortcode and print items_id=””

    Anyone has any idea where is my mistake?

  • the_field() echos the values and returns nothing to the variable,

    You need to use get_field()

    
    $parts= get_field('parts_cars', $post);
    
  • Hi John, Thank you for quick response. I just checked. I actually Used this method before and it didn’t work. That is the reason I converted ACF field as POST ID instead of OBJECT to bring data ID into Shortcode

    // with get_field result at below //

    Warning: Array to string conversion in C:path/\style-1.php on line 284
    Array

    [download_btn url=”Array”]

    // #####

    Technically I have two post

    CAR
    PART

    Parts added into CARS and Cars shown in PARTS

    I try to show ANOTHER PARTS inside Viewed part from assigned CAR brand with biderctional POST session in php

    let say The Car is Pontiac and i add three body paint bucket (yellow-green-white)

    When i enter Green paint post(PART.php) , po─▒ntiac shown Added car that pontiac

    When i enter pontiac post (CAR.PHP) green paint shown

    But I want to fetch data from CAR fields that realted directly inside PARTS to show another colors that added inside PONTIAC

    technically I reach first the CAR from PART-Template and i checked other parts that added in customfield in CAR name is car_parts

    so post IDS must fetch from CAR with FOREACH and setup_postdata
    Code is like that in singe_part.php

    $car= get_field(‘parts_car’);
    <?php if( $car): ?>

    <?php foreach( $car as $post ):
    // Setup this post for WP functions (variable must be named $post).
    setup_postdata($post); ?>

    // so now process in CAR part and check data in parts_car field
    from CAR post //

    <?php $assigned_parts_from_car_post= get_field(‘parts_car’, $post); ?>

    <?php echo do_shortcode(‘ [car-parts-1 items_number=”” external_link=”1″ category=”” items_id=”‘.$assigned_parts_from_car_post.'” columns=”4″ order=”ASC” orderby=”name” title=”Compatible Parts from CAR POST”]’); ?>

    <?php endforeach; ?>

    goes Array. If i use POST ID and the field it echo the id’s that acf works correctly but if i use get_field, it goes ARRAY

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.