Changeset 1940988
- Timestamp:
- 09/13/2018 06:27:18 PM (8 years ago)
- File:
-
- 1 edited
-
wp-autotagger/trunk/247-wp-smart-tagger.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-autotagger/trunk/247-wp-smart-tagger.php
r1939359 r1940988 183 183 jQuery( document ).ready( function( $ ) { 184 184 185 jQuery( '#woo-products' ).on( 'click', function() { 185 jQuery( '#woo-allproducts' ).on( 'click', function() { 186 console.log("all tags") 187 var checkboxValues = []; 188 var images_urls = []; 189 jQuery('input[type="checkbox"]').each(function(index, elem) { 190 checkboxValues.push($(elem).val()); 191 }); 192 jQuery('.product_image').each(function(index, elem) { 193 images_urls.push($(elem).val()); 194 }); 195 for (let i = 0; i < 10; i++) { 196 const element = checkboxValues[i]; 197 var tags = []; 198 console.log(element); 199 console.log(images_urls[i]) 200 // get tags for each image 201 jQuery.post( "http://auto-tagger.thedemo.co/api/predict/", { 202 api_key : '<?php echo esc_attr( get_option('wp-smart_tagger_option_api_key') ); ?>', 203 url: images_urls[i], 204 security: '<?php echo wp_create_nonce( "bk-ajax-nonce" ); ?>' , 205 provider : "clarafai" 206 } 207 ) .done(function( data ) { 208 209 data.forEach(e => { 210 tags.push(e) 211 }); 212 213 console.log( "tags results" ,tags ); 214 // Update Product Tags 215 jQuery.ajax({ // We use jQuery instead $ sign, because Wordpress convention. 216 url : ajaxurl, // This addres will redirect the query to the functions.php file, where we coded the function that we need. 217 type : 'POST', 218 data : { 219 action : 'Wp_Smart_Tagger_insert_action', 220 tags : tags, 221 postid : element 222 }, 223 beforeSend: function() { 224 }, 225 success : function( response ) { 226 }, 227 complete: function(){ 228 console.log("product ",i) 229 if(i == 9 ){ 230 console.log("all tagged") 231 window.location.reload(false); 232 } 233 } 234 }); 235 236 237 238 }) 239 240 } 241 console.log(checkboxValues) 242 }); 243 244 245 jQuery( '#woo-products' ).on( 'click', function() { 186 246 var checkboxValues = []; 187 247 var images_urls = []; … … 210 270 211 271 data.forEach(e => { 212 // if(e.value > 0.7){213 272 tags.push(e) 214 // }215 273 }); 216 274 … … 262 320 $postid = intval( esc_html($_POST['postid'] )); 263 321 $tags = Wp_Smart_Tagger_recursive_sanitize_text_field($_POST['tags']) ; 322 wp_set_object_terms($postid , [], 'product_tag'); 264 323 wp_set_object_terms($postid , $tags, 'product_tag'); 265 324 wp_die(); … … 287 346 288 347 ?> 289 290
Note: See TracChangeset
for help on using the changeset viewer.