You have a couple of flaws in your code
-
get_post_meta( 'fap_referral_link' )
should beget_post_meta( $post->ID, 'fap_referral_link', true )
. Please seeget_post_meta()
-
You should always first check if you actually have posts before you run your
foreach
loop -
Never ever use
extract()
. It useseval()
which stand for EVIL. This has been completely removed from WordPress core years ago due to a specific reason. It poses a big security thread. Please consult the Shortcode API for correct use. Here is an example straight from the codex on how to use a shortcode// [bartag foo="foo-value"] function bartag_func( $atts ) { $a = shortcode_atts( array( 'foo' => 'something', 'bar' => 'something else', ), $atts ); return "foo = {$a['foo']}"; } add_shortcode( 'bartag', 'bartag_func' );
Just a couple of extra notes
-
For some reason I can’t see why you would need the
global $post
. It seems totally unnecessary from looking at your code -
Also, you have
cat
in your attributes that does not get used.
EDIT
It seems that your custom field holds more than one value. The best way forward here will be to do a var_dump()
of your custom field to see what data is returned and what the exact format is of it.
Check this post I have recently done on custom fields