1 回答
TA贡献1794条经验 获得超7个赞
我想到了。虽然这对我来说是一个头疼的问题。如果其他人遇到同样的问题,请注意下面的代码。您必须创建选择,然后在您希望帖子更改为的类别上设置“已选择”选项。然后,在 CSS 中,隐藏选择输入,只留下按钮。
<?php add_shortcode('approved_button', 'approved_button_function');?>
<?php function approved_button_function() { ob_start();?>
<div class="approval">
<form action="" id="update-post" method="post">
<?php wp_dropdown_categories( "selected='categoryId'&exclude=21&class=approval-select&show_count=1&hierarchical=1&orderby=name&order=ASC&&hide_empty=0&show_option_all=Choose An Option" ); ?>
<input class="approval-button" type="submit" name="submit" value="Approve" />
</form>
</div>
<?php if ( array_key_exists('cat', $_POST )) {
global $post;
$post_id = $post->ID;
wp_set_object_terms( $post_id, intval( $_POST['cat'] ), 'category', false );
} ?>
- 1 回答
- 0 关注
- 200 浏览
添加回答
举报