Custom Post Type Loop within Shortcode

Notice: Trying to get property of non-object

Would indciate that $post has no scope inside your function. One simple solution here would be to globalise $post so it has scope, effectively fixing the error.

However, whenever you create a query, or run the loop and call the_post method this gives you access to the WordPress template tags.

Rather then put in global statements you could call get_the_ID() which should of course contain the given post’s id(ie. the current post for that iteration of the loop).

Update your problem line to read..

$custom = get_post_custom( get_the_ID() );

And that should clear up the problem, of course noting giving $post scope inside the function would also work, it just wouldn’t look as poetic!.. 😉

Small side question back to the asker, what are you looking for when you call get_post_custom, are you checking for some particular meta keys, or looping over every meta item you find? There may be some room for improvement there(if you’re interested).