Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I can write and publish posts from my frontend - everything is fine. You know the backend: write-post-style, right? There it lists all existing tags.

How can I display all existing tags at frontend and use it the same way, like in backend? Especially the function "click on one existing tag" and use it with the post, that I am currently writing?

By the way: I want to use tags from my custom-taxonomy called "wissen"...

Do you know a solution, how to use this function at frontend?

This is my code: (you can see, how i do now the tags and i hope the code is everything important [my real file is a lot more code])

The code at the beginning of my form-page:

if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {

    $title =  $_POST['title'];
    $description = $_POST['description'];
    $tags = $_POST['post_tags'];

    $new_post = array(
    'post_title'    =>  $title,
    'post_content'  =>  $description,
    'post_category' =>  array($_POST['cat']),  // Usable for custom taxonomies too
    'tags_input'    =>  array($tags),
    'post_status'   =>  'publish',           // Choose: publish, preview, future, draft, etc.
    'post_type' =>  'wissen'  //'post',page' or use a custom post type if you want to
);

    //SAVE THE POST
    $pid = wp_insert_post($new_post);

    //SET OUR TAGS UP PROPERLY
    wp_set_post_tags($pid, $_POST['post_tags']);

    //POST THE POST
    do_action('wp_insert_post', 'wp_insert_post');

}

In my body:

<form id="new_post" name="new_post" method="post" action="" enctype="multipart/form-data">

    <?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
    <textarea id="description"  name="description"></textarea>
    <textarea id="post_tags"  name="post_tags"></textarea>
    <input type="hidden" name="action" value="new_post" />
    <input type="submit" value="Eintragen" id="submit" name="submit" />

</form>
share|improve this question
    
What are you using for writing posts on the frontend? –  GhostToast Jun 4 '13 at 20:05
    
In 10 minutes there is my code in the question ;-) –  paratodo Jun 4 '13 at 20:08
add comment

1 Answer

try something like this:

<?php
$taxonomies = array( 
    'wissen_tags'
);
$args = array(
    'orderby' => 'name',
    'order' => 'ASC',
    'hide_empty' => false
);

$terms = get_terms($taxonomies,$args);

if (count($terms) > 0):
i = 0;
    foreach ($terms as $term): ?>
        <div class="wissen_tag_list">
            <input type="radio" value="<?php echo $term->term_id; ?>" name="wissen_tags" class="wissen_tag_list_ckb" <?php if ( $i == 0 ) { ?>checked<?php } ?>>
            <label class="wissen_tag_list_ckbl">
                <?php echo $term->name; ?>
            </label>
        </div>
<?php
    $i++; endforeach;
endif; ?>

Of course if you have many tags you might consider a more dynamic approach, e.g. by ajaxifing a input; and not showing the complete list always.

note:
→ you probably have to make above code fit your criteria/parameters better, not sure if I caught them all correctly;
→ additionally, above code is for selecting a single term;


edit: for multiple selections

  • change type to checkbox;
  • and make name - respectively the according $_POST variable - an array;

<input type="checkbox" value="<?php echo $term->term_id; ?>" name="wissen_tags[]" class="wissen_tag_list_ckb">

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.