dosc9472 2014-01-02 14:30
浏览 15
已采纳

如何在复选框输入值内回显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.

  • 写回答

3条回答 默认 最新

  • dsai1991 2014-01-02 14:35
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?