sherbert Posted July 30, 2009 Share Posted July 30, 2009 Hi, I'm just starting to learn php. I'm using a Wordpress theme that allows members of my site to post ads. The post-form allows them to type in keyword tags (which then get displayed within their published post as links, which when clicked, show a page with all posts sharing the same tag). I want to have checkboxes for specific tags in the post-form. The tags text input field in the post-form.php looks like this: <label for="post_tags"><?php _e('Tags','cp'); ?> <small><?php _e('(separate with commas)','cp'); ?></small></label> <input type="text" id="post_tags" class="adfields" name="post_tags" size="60" maxlength="100" value="<?php echo $_POST['post_tags']; ?>" /> I noticed the form_process.php contains this: $post_tags = cp_filter($_POST['post_tags']); and this also in form_process.php: $post_id = wp_insert_post( array( 'post_author'=> $user_id, 'post_title'=> $post_title, 'post_content'=> $description, 'post_category'=> $post_cat_array, 'post_status'=> $post_status, 'tags_input'=> $post_tags I have tried adding this to the post-form.php: <label for="post_tags"><?php _e('Tags ','cp'); ?></label> <input type="checkbox" name="post_tags" value="Monday" />Monday<br /> <input type="checkbox" name="post_tags" value="Tuesday" />Tuesday<br /> When Monday and Tuesday are both checked, only the lower one (Tuesday) gets associated with the post. I've been reading about how I need to set this up as an array (name="post_tags[]") but I'm still not sure how to go about it, especially how to receive it in form_process.php Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/168078-multiple-checkbox-tag-selection-in-a-wordpress-post-form/ Share on other sites More sharing options...
sKunKbad Posted July 30, 2009 Share Posted July 30, 2009 Of course only one is posted, because they both have the same name. Quote Link to comment https://forums.phpfreaks.com/topic/168078-multiple-checkbox-tag-selection-in-a-wordpress-post-form/#findComment-886576 Share on other sites More sharing options...
sherbert Posted July 30, 2009 Author Share Posted July 30, 2009 Using the same name seems to be ok, at least now that I've included [] I have got the multiple checkbox array working. In form_process.php I have this: $checkbox_tags= ($_POST['checkbox_tags']); ------------------ And in post-form.php I have this: <input type="checkbox" name="checkbox_tags[]" value="Wednesday" />Wednesday<br /> <input type="checkbox" name="checkbox_tags[]" value="Thursday" />Thursday<br /> <input type="checkbox" name="checkbox_tags[]" value="Friday" />Friday<br /> -------------------- I see now that the following part of form_process.php is what makes the tags be associated with the post: 'tags_input'=> $checkbox_tags ------------------------------ Now how can I get 'tags_input' to include both $checkbox_tags, and also $post_tags ? As this will allow me to have the checkbox tags pooled with the tags entered into the text field. Quote Link to comment https://forums.phpfreaks.com/topic/168078-multiple-checkbox-tag-selection-in-a-wordpress-post-form/#findComment-886705 Share on other sites More sharing options...
sKunKbad Posted July 31, 2009 Share Posted July 31, 2009 Since $checkbox tags is now an associative array's value, The name of which I am not certain, I will call that array $theArray. So to access the values of $theArray['tags_input'], you would need to loop through $theArray['tags_input']. $x = 0; foreach($theArray['tags_input'] as $checkbox_tag){ echo "$checkbox_tag is the value of the array element in position # $x."; $x++; } You could bypass this loop and get straight at the values by doing something like this: if(isset($checkbox_tags){ echo $checkbox_tags['0']; echo $checkbox_tags['1']; // etc..... } Quote Link to comment https://forums.phpfreaks.com/topic/168078-multiple-checkbox-tag-selection-in-a-wordpress-post-form/#findComment-887389 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.