如何在复选框输入值内回显Wordpress标题?

I'm using custom post types and meta data and need to define the value of a form checkbox to be the title of the post.

echo '<input type="checkbox" name="activityType" value="'.the_title().'" />';

Calling this inside of the loop seems like it should work. Not much luck passing it through though.

the_title will echo the title instead of returning it, you can work around this by ending the PHP Block and using the_title inline

?><input type="checkbox" name="activityType" value="<?=the_title();?>" /><?php

Or set the $echo argument of the_title to false to return the value

echo '<input type="checkbox" name="activityType" value="'.the_title('','',false).'" />';

http://codex.wordpress.org/Function_Reference/the_title

Try this :

echo get_the_title($ID);

This function will return the title of a post for a given post ID. If the post is protected or private, the word "Protected: " or "Private: " will be prepended to the title. It can be used inside or outside of The Loop. If used outside the loop an ID must be specified.

Read : http://codex.wordpress.org/Function_Reference/get_the_title

If you want to get the title outside of The Loop you need to use get_the_title

The documentation explain's it the_title()

Regards