【发布时间】:2015-08-18 20:10:59
【问题描述】:
我整天都在研究这个并没有找到一个优雅的解决方案,我想做的是在前端的现有帖子上标记一个用户 ID(使用 Wordpress)。该过程将遵循...
- 帖子有一个文本输入和提交按钮(前端)。
- 用户(已注册),在文本字段中输入标签并提交
- 标签被写入帖子,(理想情况下不使用 ajax 进行刷新,但不是必需的。)
看起来应该是直截了当的,但我找不到任何相关信息,在此先感谢。
编辑:工作,最终代码如下所示,谢谢!
<form name="primaryTagForm" id="primaryTagForm" method="POST" enctype="multipart/form-data" >
<fieldset>
<input type="text" name="newtags" id="newtags" value="true" />
<?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
<button class="button" type="submit"><?php _e('Tag Product', 'framework') ?></button>
</fieldset>
</form>
<?php
// If a user is logged in, and a form has been submitted with new tags
if ( is_user_logged_in() && isset( $_POST['newtags'] ) ) {
// Add the tags
wp_set_post_tags(get_the_ID(), sanitize_text_field($_POST['newtags']), true );
} ?>
【问题讨论】: