using get_post_meta() inside functions.php does not work why?…
-
Hello,
I am trying to read out a value from a custom field inside the functions php.
The code worked fine in the index.php but stopped working when I tried to put it in the functions php. To my surprise “echo get_post_meta($post->ID, ‘link’, true);” did not return a value. So I am wondering if the use of get_post_meta() is possible inside a function. If there are other ways to find out if there is a custom field inside a function please let me know.Thanks,
This is what I have so far in functions.php with custom field id name ‘link’…
<?php function s_the_title(){ $var = get_post_meta($post->ID, 'link', true); if ($var == '') { $field_value = get_permalink(); } else { $field_value = $var; } // echo '<a href="'; echo $field_value; echo '" rel="bookmark" title="Find out more about '; the_title(); echo '">'; echo the_title(); echo '</a>'; } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘using get_post_meta() inside functions.php does not work why?…’ is closed to new replies.