Created
March 15, 2010 17:36
-
-
Save artlung/333087 to your computer and use it in GitHub Desktop.
is it possible to pass the value of a custom field to a function in functions.php?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>is it possible to pass the value of a custom field to a function in functions.php?</p> | |
<p>Way #1</p> | |
<?php | |
// one way would be to pass in the post ID | |
function yourSpecialFunction($post_id) { | |
$custom_field = get_post_meta($post_id, 'my_custom_field', true); | |
// do something with $custom_field | |
return; | |
} | |
?> | |
<!--Then when you call it, say in the loop:--> | |
<?php yourSpecialFunction(get_the_ID()); ?> | |
<p>Way #2</p> | |
<?php | |
// another way would be to get the value and pass it in | |
function yourSpecialOtherFunction($custom_field) { | |
// do something with $custom_field | |
return; | |
} | |
?> | |
<!--Then when you call it, say in the loop:--> | |
<?php | |
$custom_field = get_post_meta(get_the_ID(), 'my_custom_field', true); | |
yourSpecialOtherFunction($custom_field); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment