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 created a meta box that allows users to add an additional name/id to their post. From what I can tell it is adding the meta information correctly because when I edit a post that has a custom name/ID it shows up in the input box by default as it should.

So my issue is that I am trying to pull the custom ID/name and use it as an additional ID tag in the code. Although it is not retrieving anything. When I use the code in my theme and check the html on the page the ID is showing ID="". So for some reason it is not pulling anything. Can anyone see an issue?

<?php $post_id = get_the_ID(); ?>
    <?php $value = get_post_meta($post_id, 'newtheme_section_id'); ?>
    <id="<?php $value; ?>">

If I change get_the_ID() to the_ID() then it returns a value but it is the post ID instead of the custom id the user entered into the feild.

EDIT: I was able to figure it out by echoing the function instead of storing it in a variable, along with Mannys suggestion . Here is the updated code.

<?php $post_id = get_the_ID(); ?>
<id="<?php echo esc_attr( get_post_meta($post_id, 'newtheme_section_id', true) ); ?>">
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Make sure you include the third argument to get_post_meta, a Boolean that determines whether or not it returns a single item or an array of items. The default is false, which is an array, so set it to true:

  <?php $value = get_post_meta ($post_id, 'newtheme_section_id', true ); ?>
share|improve this answer
    
Thanks, I added it but unfortunately I am still having the same issue. –  user1632018 Apr 21 '13 at 4:02
    
I was able to echo the function instead of storing it(output) in a variable. I had tried this before your suggestion and it did not work, so I am marking your post as the answer. –  user1632018 Apr 21 '13 at 4:15

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.