Function

<?php $img_id = get_post_custom_values('img'); foreach ( $img_id as $key => $value ) { echo $value; } ?> 

returns me a number - image id. It is necessary to write down 4 similar IDs with a comma in the following code

 <?php echo do_shortcode('[gallery ids='']'); ?> 
  • exactly four, or for you for example at least four? - Wayer
  • @Wayer have 4 similar parameters for the record - img1, ..., img4, all of them must be passed in the form of strings, comma separated - malginovdesign

1 answer 1

Try this:

 <?php $img_id = get_post_custom_values('img'); foreach ( $img_id as $key => $value ) { if(++$i > 4) break; $string_with_ids .= $value; if($i < 4) $string_with_ids .= ','; } ?> 
  • I put this code in quotes? - malginovdesign
  • I am sorry, did not finish. <?php echo do_shortcode("[gallery ids='$string_with_ids']"); ?> <?php echo do_shortcode("[gallery ids='$string_with_ids']"); ?> - Wayer