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 function set up to place some standard text in each post for a Custom Post Type. However, within that standard text I want to pull some unique text from a few custom fields. Not sure what is wrong with my code:

function default_content($content) {
  global $post;
  if ($post->post_type == 'my-custom-post-type') {
    $content .= '<p style="text-align: center;"><strong>Custom Field Text here: <?php echo get_post_meta( get_the_ID(), \'custom-field-1\', true )</strong></p>
    <p style="text-align: center;"><a href="http://myblog.com/?checkout=<?php echo get_post_meta( get_the_ID(), \'custom-field-2\', true )">Link 01</a></p>';
  }
  return $content;
}
add_filter('the_content', 'default_content', 0);
share|improve this question

1 Answer 1

up vote 0 down vote accepted

You are trying to echo within a variable. You also have encapsulated PHP tags in the string as well. You need to concatenate just the functions themselves like this:

    function default_content($content) {
        global $post;

        if ($post->post_type == 'my-custom-post-type') {
            $content .= '<p style="text-align: center;"><strong>Custom Field Text here: '. get_post_meta( $post->ID, "custom-field-1", true ).'</strong></p>
                         <p style="text-align: center;"><a href="http://myblog.com/?checkout=' . get_post_meta( $post->ID, "custom-field-2", true ).'">Link 01</a></p>';
        }
        return $content;
    }
    add_filter('the_content', 'default_content', 0);

Also you are calling global $post, so use $post->ID instead of get_the_ID().

Cheers!

share|improve this answer
    
Perfect, thank you! I am slowly but surely getting the hang of this WordPress thing (I think)! Much appreciated on the help. –  George C Sep 16 '11 at 5:04
    
No worries. :) That's why we're here. Everyone has to start somewhere. –  Brian Fegter Sep 16 '11 at 5:06

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.