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.

Im trying to create a template tag for a subheading for a post which is entered as a custom field.

This is the function I have:

function spost_subheading() {
$key = get_post_meta($post->ID, '_subheading', true);
    if ($key != '') { 
        echo $key; 
    } 
    else {} 
}

But I'm getting these two errors when I use spost_subheading(); in the loop and it doesn't output any subheading.

  • Notice: Undefined variable: post in C:\wamp\www\wordpress\spost\wp-content\themes\spostfeb14\inc\template-tags.php on line 135
  • Notice: Trying to get property of non-object in C:\wamp\www\wordpress\spost\wp-content\themes\spostfeb14\inc\template-tags.php on line 135

(line 135 is the line that begins $key = get_post_meta...)

Any help or advice would be much appreciated?

share|improve this question
    
I wonder if its better to just ask questions on Stack Overflow instead of Wordpress Answers :( .... –  user1515699 Feb 19 at 7:43

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.