Searching JQuery arrays of taxonomy terms for word matches in frontend images upload
I have a need to search through 4 different Taxonomy terms for matches of image tags. Using Jquery.
Having hundereds of images to upload and tag and the theme I'm usings back end has a problem(multiple posting for each post type), I have added a hook to the wordpress exif imagemeta data, using the copyright exif tag.
function hk_filter_add_exif($meta, $file, $sourceImageType)
{
if ( is_callable('exif_read_data')
in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)) ) )
{
$exif = @exif_read_data( $file );
if (!empty($exif['Copyright'])) $meta['tags'] = $exif['Copyright'] ;
return $meta;
}
}
and (Short Term) adding to function wp_prepare_attachment_for_js in media.php
$ptags = $meta['image_meta']['tags'];
'PWTags' = $ptags,
This makes tagging the images on computer in bulk so much easier than one at a time, in admin.
so for example, in the copyright EXIF tag, I put childrens,white,pink,contempory.
Bedroom, being the room, childrens being a feature pink being a color and contempory being a style.
Each have a taxonomy.
Now when I upload an image from front end, I get the following in the console.log:
PWTags:"childrens,white,pink,contempory"
alt:""
author:"3"
authorName:"Gabpy"
caption:"bedroom"
title:"chpk2171134-3"
type:"image"
uploadedTo:0
uploading:false
url:"http://**************/wp-content/uploads/chpk2171134-3.jpg"
width:1600
PWTags:"childrens,white,pink,contempory" being the key of this request for help. I might add that the number of tags could be multiple for each taxonomy, like PWTags:"childrens,white,pink,contempory" giving 1 feature, 2 colors and and one style..
I need to search through the four taxonomies terms for a match for each word in PWTags, if found, pushed together and then inserted into the input values below.
jQuery.each( attachments,function(key,value){
var full = value.sizes.full.url,
imageID = value.id,
thumbnail = value.sizes.thumbnail.url,
name = value.name,
title = value.title,
room_type = value.caption,
pwTags = value.PWTags;
holder += "li class='gallery-thumb'" +
"div class='gallery-thumb-holder'" +
"a class='mark-featured' data-property-id='0' data-attachment-id='"+imageID+"' href='#mark-featured'i class='fa fa fa-star-o'/i/i/a" +
"span class='my_delete1' data-attachment-id='"+imageID+"'i class='fa fa-times-circle'/i/span" +
"img src='"+thumbnail+"' exif='true'/" +
"input class='dt-image-name' type='text' name='items_name[]' value='"+title+"' /" +
"/div" +
"div class='input-holder'"+
"labelTags/labelinput class='dt-image-tags' type='text' name='items_tags[]' value='"+pwTags+"'/" +
"labelRoom Type/labelinput class='dt-image-colors' type='text' name='items_image_room_group[]' value='"+room_type+"' /" +
"labelColors/labelinput class='dt-image-colors' type='text' name='items_image_colors[]' value='"+colors+"' /" +
"labelFeatures/labelinput class='dt-image-colors' type='text' name='items_image_features[]' value='"+features+"' /" +
"labelStyles/labelinput class='dt-image-colors' type='text' name='items_image_styles[]' value='"+styles+"' /" +
"input type='hidden' name='items[]' value='"+full+"' /" +
"input type='hidden' name='items_thumbnail[]' value='"+thumbnail+"' /" +
"input type='hidden' name='items_id[]' value='"+imageID+"' /" +
"/li";
I have created four localized variables containing each list of taxonomy terms, for example: (Not sure if this is the right way to go, but only way I could think of getting the terms to searchable via Jquery)
var imageColors = ["black","blue","brown","colourful","cream","green","grey","pink","red","white","yellow"];
var imageRooms = ["bathroom","bedroom","kitchen","outdoor-space","reception"];
var imageFeatures = ["childrens","feature-fireplace","feature-lighting","feature-staircase","great-view","home-office","hotel-chic","loft-living","open-plan","outdoor-living","small","statement-bath","statement-wallpaper","statement-wallpraper","swimming-pool"];
var imageStyles = ["contemporary","country","quirky","traditional"];
And have been trying to search each taxonomy variable with pwTags, all to no avail, not being very converse in JQuery, its a struggle. Hope thats not too confusing and as always, any help is greatly appreciated.
Topic plupload custom-taxonomy jquery Wordpress
Category Web