8 posts
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
ThemeRain says

Hi, I try to get all titles value from metabox, but i get “Invalid argument supplied for foreach()” and only last title from array.

$wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => '3')); while($wp_query->have_posts()) : $wp_query->the_post(); $slides = get_post_meta($wp_query->post->ID, 'meta_box_gallery', true); foreach($slides as $slide) { $gallery = $slide['title']; } $gallery endwhile;
70 posts Talk less do more!
  • Has referred 10+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
Rifki says

Maybe the problem is get_post_meta($wp_query->post->ID, 'meta_box_gallery', true); try with this: get_post_meta($post->ID, 'meta_box_gallery', true);. Good luck!

8 posts
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
ThemeRain says

Unfortunately no, with WP_Query I need to use $wp_query->post->ID

70 posts Talk less do more!
  • Has referred 10+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
Rifki says

Check the array values, make sure that is not an empty array. print_r( $slides );

8 posts
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
ThemeRain says

I checked, array not empty.

8 posts
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
ThemeRain says

print_r($slides) show me:

Array ( [0] => Array ( [title] => 1 [upload_gallery_image] => http://website.com/image1.jpg ) [1] => Array ( [title] => 2 [upload_gallery_image] => http://website.com/image2.jpg ) )
70 posts Talk less do more!
  • Has referred 10+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
Rifki says

Hmm.. I think this is what you’re looking :

$wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => '3')); 

while($wp_query->have_posts()) : $wp_query->the_post();
    $slides = get_post_meta($wp_query->post->ID, 'meta_box_gallery', true); 

    foreach($slides as $slide) { 
        $gallery = $slide['title']; 

        // let show
        echo "Title: $gallery \n";
    } 
endwhile;

Edit: The code above works for me

8 posts
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
ThemeRain says

It’s not help :(

8 posts
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
ThemeRain says

Yeah, edited code is works, that’s great! But how I can put this values instead $gallery not using echo?

$thumbnail = '<div class="rain">$gallery</div>

70 posts Talk less do more!
  • Has referred 10+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
Rifki says
You can do with:
$thumbnail = '<div class="rain">'.$gallery.'</div>';

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by