Jump to content

Recommended Posts

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.

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.

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.....
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.