Get custom field outside the loop array

2019-09-20 09:59发布

问题:

I'm trying to the $appLink variable with a custom field value outside of the loop. I'm using Wurfl to detect the users device, I'd like to echo the custom field value for the URL. This is what I have but I can't get it to work. Can anyone help please?

 else if ($os == 'iOS') 
  {  
  global $wp_query;
  $postid = $wp_query->post->ID;
  $appLink = echo get_post_meta($postid, 'ios_app_link_sb', true);
  wp_reset_query();
  } 

回答1:

It should be either

 echo get_post_meta($postid, 'ios_app_link_sb', true);

or

 $appLink = get_post_meta($postid, 'ios_app_link_sb', true);
 echo $appLink;


回答2:

Try this debug $postid.

Print_r($id)

if $postid is true, you check name key meta 'ios_app_link_sb' is exist value?



标签: php wordpress