Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom field for my post and I am trying to output it onto my post's page but nothing appears. I know my code works otherwise if instead of trying to call my custom field, I use a fixed string.

My custom field key has an id of

_dad_wysiwyg

I am using this to try to display the value of the key from within functions.php:

add_action( '__after_content' , 'add_dad_cents' );
function add_dad_cents() {
    echo get_post_meta($post->ID, '_dad_wysiwyg', true);
}

I know the key has a value by looking at my postmeta table in my database. The value of the key is

<p>test</p>

Logically, after my post content, I'd expect to see the above string but nothing appears. As I stated, if I change my function to echo a string, I see the string where expected after my post content.

edit: It appears $post is empty. Clearly, I need help calling the post ID from functions.php...

Can anyone help me figure out how to call the value?

Thanks!

share|improve this question
1  
What is the value of $post inside your function? –  Milo Jun 6 at 17:22
    
$post would appear to be empty. Clearly this is the source of my problem. How do I get the post ID if the function is inside functions.php? –  Sweepster Jun 6 at 21:55

1 Answer 1

Problem solved.

Added the following to my function:

global $post;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.