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
The topic ‘Topic tags removed from current post, frontend javascript/php/ajax?’ is closed to new replies.