This answer does exactly what I needed to do, but the only thing is I need it to select more than just one category.
So I have changed the code to work based on salary so salary gets entered into a custom field, then it automatically selects the salary banding category which works fine, but now I have a salary from and a salary to custom field so I have a value of salary to, so how can I get the code to add the post to mulitiple categories based on both values if that makes any sense?
Below is my code that works for the category selection based on the value of salaryband, so I need it to also select the category based on salaryband2 (custom field)
function add_my_taxonomy($post_ID) {
$salary = array(
'1015' => '10 - 15 ph',
'100140' => '100K - 140K',
'101120' => '101K - 120K pa',
'121150' => '121K – 150K pa',
'151170' => '151K – 170K pa',
'171200' => '171K – 200K pa',
'2025' => '20 – 25 ph',
'2025k' => '20K – 25K pa',
'2630' => '26 – 30 ph',
'2630k' => '26K – 30K pa',
'3040' => '30 – 40 ph',
'3140k' => '31K – 40K pa',
'4150' => '41K – 50K pa',
'5160' => '51K – 60K pa',
'6170' => '61K – 70K pa',
'7180' => '71K – 80K pa',
'8190' => '81K – 90K pa',
'91100' => '91K – 100K pa'
);
$zip = array(
'1015' => '10, 11, 12, 13, 14, 15,',
'100140' => '101000, 102000, 103000, 104000, 105000, 106000, 107000, 108000, 109000, 110000, 111000, 112000, 113000, 114000, 115000, 116000, 117000, 118000, 119000, 120000, 121000, 122000, 123000, 124000, 125000, 126000, 127000, 128000, 129000, 130000, 131000, 132000, 133000, 134000, 135000, 136000, 137000, 138000, 139000, 140000,',
'101120' => '101000, 102000, 103000, 104000, 105000, 106000, 107000, 108000, 109000, 110000, 111000, 112000, 113000, 114000, 115000, 116000, 117000, 118000, 119000, 120000,',
'121150' => '121000, 122000, 123000, 124000, 125000, 126000, 127000, 128000, 129000, 130000, 131000, 132000, 133000, 134000, 135000, 136000, 137000, 138000, 139000, 140000, 141000, 142000, 143000, 144000, 145000, 146000, 147000, 148000, 149000, 150000,',
'151170' => '151000, 152000, 153000, 154000, 155000, 156000, 157000, 158000, 159000, 160000, 161000, 162000, 163000, 164000, 165000, 166000, 167000, 168000, 169000, 170000,',
'171200' => '171000, 172000, 173000, 174000, 175000, 176000, 177000, 178000, 179000, 180000, 181000, 182000, 183000, 184000, 185000, 186000, 187000, 188000, 189000, 190000, 191000, 192000, 193000, 194000, 195000, 196000, 197000, 198000, 199000, 200000,',
'2025' => '20, 21, 22, 23, 24, 25,',
'2630' => '26, 27, 28, 29, 30,',
'2025k' => '20000, 21000, 22000, 23000, 24000, 25000,',
'2630k' => '26000, 27000, 28000, 29000, 30000,',
'3040' => '31, 32, 33, 34, 35, 36, 37, 38, 39, 40,',
'2630k' => '26000, 27000, 28000, 29000, 30000,',
'3140k' => '31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000,',
'4150' => '41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000,',
'5160' => '51000, 52000, 53000, 54000, 55000, 56000, 57000, 58000, 59000, 60000,',
'6170' => '61000, 62000, 63000, 64000, 65000, 66000, 67000, 68000, 69000, 70000,',
'7180' => '71000, 72000, 73000, 74000, 75000, 76000, 77000, 78000, 79000, 80000,',
'8190' => '81000, 82000, 83000, 84000, 85000, 86000, 87000, 88000, 89000, 90000,',
'91100' => '91000, 92000, 93000, 94000, 95000, 96000, 97000, 98000, 99000, 100000,'
);
foreach ($zip as $code => $salaryband){
$salaryband = explode(',', $salaryband);
$customField = get_post_meta($post_ID,'salaryband',true);
if (in_array($customField,$salaryband)){
wp_set_object_terms( $post_ID, $salary[$code], 'salary' );
}
}
salary
and you want to set two fields based on that? What are the relationships? Why does your code only try to set one field?