我搜索了网站,看看我是否能找到一个有类似问题的帖子,但我没有运气。所以这是我的问题。
我有一个功能
function formStatus($status){ ?>
<fieldset name="status">
<label for='status'>Post Status</label>
<span>* <?php _e('Would you like your post to be reviewed and then published? Or do you plan on working on it more later?','Item');?></span>
<p>
<input type="radio" name="status" value="pending" id="inspiration-status_0" <?php if($status=='pending'){echo "checked";}?>/>
Submit for review and publish.
<br />
<input type="radio" name="status" value="draft" id="inspiration-status_1" <?php if($status=='draft'){echo "checked";}?>/>
Save as draft
<br />
<?php
if(current_user_can( 'manage_options' ) || $status=="publish" ){ ?>
<input type="radio" name="status" value="publish" id="inspiration-status_2" <?php if($status=='publish'){echo "checked";}?>/>
Publish
</p>
</fieldset>
<?php }}
此功能的目的是在我的表单中创建一个单选按钮元素,供我的博主将其状态设置为草稿或待定,如果他们是管理员,也可以发布。表格完美显示。
当用户添加新内容时,无线电元素不会将变量传递到$ _POST。在提交方面,我有这个:
$status = $_POST['status'];
$new_article = array(
'post_title' => $title,
'post_content' => $description,
'post_status' => $status,
'post_category' => $categories,
'tags_input' => $tags,
'post_author' => $current_user->ID
);
$article_id = wp_insert_post($new_article);
我看起来很清楚,但由于某种原因,它没有从单选按钮接收值。我甚至试图回显$ status以查看它所持有的值,并且它没有显示,这意味着它没有任何价值。
通过这个提供的代码,有人可能会收集为什么价值没有发送到$ _POST [&#39;状态&#39;]变量?
提前感谢所有的帮助!! :)
生成函数的HTML
<fieldset name="status">
<label for='status'>Post Status</label>
<span>* Would you like your post to be reviewed and then published? Or do you plan on working on it more later?</span>
<p>
<input type="radio" name="status" value="pending" id="inspiration-status_0" />
Submit for review and publish.
<br />
<input type="radio" name="status" value="draft" id="inspiration-status_1" />
Save as draft
<br />
<input type="radio" name="status" value="publish" id="inspiration-status_2" />
Publish
</p>
</fieldset>
更新:
我遗漏了一些我为检查空字段所做的错误处理,因为我认为它不相关。我错了。
if($title=='' || $tldr=='' || $description=='' || $status=='' || count($tags)==0 || count($categories)==0){
问题在于它说$ status ==&#39;&#39 ;;我有$ status =&#39;&#39;的错字。每次重新加载时,它都会将$ status重置为空白。
问题是缺少&#39; =&#39;