• Resolved mogito

    (@mogito)


    Hello, could some kind soul point me in the right direction by any chance….?

    I have this code added to my functions file. This is to ADD a custom field to the content but it doesn’t seem to work ?? . Can anyone see anything wrong with this code?

    function added_content($content) {
       $customimage = get_post_meta($post->ID, 'Images', true);
       $content = $content . $customimage ;
       return $content;
    }
    add_filter( 'the_content', 'added_content' );

    Thanks for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Yes – where is $post->ID supposed to be coming from?

    Thread Starter mogito

    (@mogito)

    Hi Esmi.

    Hrmmmmm………well….the short answer is, i don’t know.

    Appologies for the ignorance but I took the get_post_meta() function from my theme template – where it works fine, BUT ….now im realising that’s because it was within the loop. Woops.

    …..How would i get this to work as if it were inside the loop?

    HUGE newbie to php – struggling through….

    Try:

    function added_content($content) {
       global &post;
       $customimage = get_post_meta($post->ID, 'Images', true);
       $content = $content . $customimage ;
       return $content;
    }
    add_filter( 'the_content', 'added_content' );
    Thread Starter mogito

    (@mogito)

    Woo…it works – your a legend!

    So….i guess i need to remember to call the global post variable.

    i WILL remember this for next time.

    Thanks for your time esmi.

    Struan

    No problem. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘A helping hand.’ is closed to new replies.