Skip to content

Instantly share code, notes, and snippets.

@onishiweb
Created September 26, 2012 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onishiweb/3786419 to your computer and use it in GitHub Desktop.
Save onishiweb/3786419 to your computer and use it in GitHub Desktop.
WordPress post meta if statement
<?php
// Perform the get meta inside the condition of the if statement,
// it will return true if there's a value, false if not,
// and if true the $meta variable will be set to the meta value
if( $meta = get_post_meta($post_id, 'meta_name', true) ):
echo $meta;
else:
// Do something else
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment