I deduced in WordPress an array with id pictures:

var_dump ($gt3_theme_pagebuilder["post-formats"]["images"]); 

Conclusion:

 array(3) { [78]=> array(1) { ["attach_id"]=> string(4) "1739" } [279]=> array(1) { ["attach_id"]=> string(4) "2457" } [280]=> array(1) { ["attach_id"]=> string(4) "2458" } } 

Now I want to display pictures of all the photos by their ID:

 foreach ($gt3_theme_pagebuilder as $key => $foto_id) { wp_get_attachment_image ($foto_id); } 

This code does not work. What am I doing wrong?

    1 answer 1

    You yourself led the structure of the variable ...

    At the input of the wp_get_attachment_image() function, an integer is expected, and you are passing an array. You think that the $foto_id variable in your loop contains the ID of the photo, and in fact there is an array of the form ["attach_id" => "1739"] . To get the ID, you need to access it by the key attach_id .

    Here is the corrected code:

     $gt3_theme_pagebuilder = [ 78 => [ "attach_id" => "1739" ], 279 => [ "attach_id" => "2457" ], 280 => [ "attach_id" => "2458" ] ]; foreach ($gt3_theme_pagebuilder as $key => $foto) { wp_get_attachment_image($foto['attach_id']); } 
    • Yes, thanks, already disassembled. I put the right pictures on the post page, everything is as it should, but now you need to make a slider gallery and zoom effect with a click on it, do you have any ideas?) Plugins ready for WP lightbox 2 do not work, here is the site on get pagebuilder and it displays pictures outside the box, therefore rewrite plugin, theme, etc. I already have a conclusion, now 3 fad. Slider do, and zoom effect, I will try. - BonBonSlick
    • This is another question. If my answer helped you, please vote for it and mark it correct (checkbox to the left of the answer). - VenZell
    • @BonBonSlick, I forgot to mention you in the comment above. Read it, please. - VenZell
    • @ VenZell okay, thanks, noted. - BonBonSlick