Title: Topic tags removed from current post, frontend javascript/php/ajax?
Last modified: June 7, 2018

---

# Topic tags removed from current post, frontend javascript/php/ajax?

 *  Resolved [futur3int](https://wordpress.org/support/users/futur3int/)
 * (@futur3int)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/topic-tags-removed-from-current-post-frontend-javascript-php-ajax/)
 * Hi everyone,
 * Simply said, I would like to run a php function such as wp_remove_object_terms
   in order to remove tags of a current post but inside a javascript function.
 * I am using taggle.js (Big Up to Sean Coker) to create tags in a current post 
   from a frontend form and it is working pretty well.
 * Using taggle.js with the following function I can log the tag data into a #log
   div when I remove a tag:
 *     ```
       onTagRemove: function(e, tag) {
         			var log2 = $('#log').html(tag);} 
       ```
   
 * My idea was to add a php function such as <?php wp_remove_object_terms( $id, 
   $terms, $taxonomy ); ?> So each time I remove a tag from the taggle.js the tag
   would be also removed from the current post. This is actually what I am aiming
   to do.
 * > The PHP function is working when I use just a tag term but not if i use any
   $variable for it…
 * In my research I’ve been lead into Ajax. So I did give a try.
    To check the PHP
   response I am using the log console as shown in the below code.
 * Ajax code:
 *     ```
           $.ajax({
               type: 'post',
               url: 'ajax.php',
               data: {
                   source: tag
               },
               success: function( data ) {
                   console.log( data );
               }
           });
   
           }
       ```
   
 * and my ajax.php code:
 *     ```
       $tag = $_POST['source'];  
        echo $tag;
       ```
   
 * > This simple code is working as it shows the removed tag in the console each
   time I remove a tag.
 * My issue:
    **When I add the function wp_remove_object_terms ( $postid, $tag, ‘
   post_tag’ ); in ajax.php it results as an error 500. **
 * Id like to be able to do similar edit/remove on tags like the Topic Tags on this
   forum.
    Can I even use <?php wp_remove_object_terms( $id, $terms, $taxonomy );?
   > with a variable for $terms?
 * Any clue would be really appreciated!
 * TY
    -  This topic was modified 7 years, 11 months ago by [futur3int](https://wordpress.org/support/users/futur3int/).
    -  This topic was modified 7 years, 11 months ago by [futur3int](https://wordpress.org/support/users/futur3int/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/topic-tags-removed-from-current-post-frontend-javascript-php-ajax/#post-10375528)
 * Ajax in WP is a little different than generic Ajax seen on most sites. If your
   Ajax handler needs to use WP functions, you must do this the WP way. General 
   documentation on Ajax in WP is in the [Plugin handbook](https://developer.wordpress.org/plugins/javascript/ajax/).
 * One thing you must certainly do is have your jQuery submit to /wp-admin/admin-
   ajax.php. Your data must include an “action” value. Your handler is then added
   as an action hook to an action tag constructed from the passed “action” value.
   That’s the short and sweet of it. Details are in the linked docs of course.
 *  Thread Starter [futur3int](https://wordpress.org/support/users/futur3int/)
 * (@futur3int)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/topic-tags-removed-from-current-post-frontend-javascript-php-ajax/#post-10378841)
 * Hello BC,
 * Thank you for the link. I didn’t realised that WordPress allow Ajax to be used
   under a specific way. I’ll look deeper into this. TY

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Topic tags removed from current post, frontend javascript/php/ajax?’ 
is closed to new replies.

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [remove](https://wordpress.org/support/topic-tag/remove/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [futur3int](https://wordpress.org/support/users/futur3int/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/topic-tags-removed-from-current-post-frontend-javascript-php-ajax/#post-10378841)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
