Your form is using ‘get’ ( $_GET
), but addcat.php
is looking for $_POST
values. That is never going to work. But beyond that, you’ve got a pretty convoluted thing going on here. You don’t really both the hooked function and addcat.php
. You need one or the other, and the hooked function is probably the better idea. Something like:
function addPostToCategoryLauncher() {
global $_GET;
if (isset($_GET['cat']) && isset($_GET['postID')) { // I am assuming that 'cat' is the correct parameter name
wp_set_object_terms( $_GET[postID], $_GET['cat'], 'category' ,true);
}
}
add_action( 'init', 'addPostToCategoryLauncher' );
You will need to send the postID with your form submission.
<form action="<?php bloginfo('url'); ?>/addcat.php" method="get">
<input type="hidden" name="postID" value="<?php echo $post->ID; ?>" ?>
<div>
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=0&orderby=name&echo=0&child_of=28&hide_empty=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange="return this.form.submit()">", $select);
echo $select;
?>
<noscript><div><input type="submit" value="View" /></div></noscript>
</div>
</form>
These are barebones functions. You need to incorporate some sanity checking for the $_GET
values and you really should use nonces as well.
I’ve made some assumptions about how your code works so there could be glitches and there may be a better hook that init
but I’d have to look around.
Try that.