Store Advanced Image IDs as Variable, Pass to Shortcode Arg as Array

Support General Store Advanced Image IDs as Variable, Pass to Shortcode Arg as ArrayResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #39560
    Jason RyanJason Ryan
    Participant

    Hello -

    I am using an Advanced Image field so the client can add multiple images to a post (project photos) and I am currently using the normal way to dump this into a custom template file, this is fine.

    However, I need to change things up and was wondering if it is possible to dump the Image IDs as an array into a shortcode arg?

    Example:

    [project_photos id="200,201,202,203" size="full"]

    Maybe set a variable for the photos to get the array of IDs:

    $p_photos = rwmb_the_value( 'my_field_id', id_array(?) );

    Then pass the variable into the arg like so:

    do_shortcode([project_photos id="' . $p_photos . '" size="full"]);

    Couldn't find anything in the docs so I figured I'd ask here (also asked on FB).

    Thanks in advance.

    #39585
    Jason RyanJason Ryan
    Participant

    *bump*

    I figured this would be an easy one!? No takers?

    #39587
    PeterPeter
    Moderator

    Hello Jason,

    The helper function rwmb_ will return a useful array of image info

    So if you want to get the image ID only, please consider using the WordPress function get_post_meta(), then use the join() function to convert it to a string and pass it to the shortcode attribute. For example:

    $p_photos = get_post_meta( get_the_ID(), 'my_field_id' ) ;
    $p_photos = join( ',', $p_photos );
    #39605
    Jason RyanJason Ryan
    Participant

    Peter -

    Thanks for the information, not sure I thought I had to stick with MB to accomplish this. I'll give this go!

    Much appreciated.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.