Appending arrays in PHP -


i have 3 arrays represent category ids in wordpress, format $base_cat_id['term_id']. want assign post 3 of these categories using following function:

wp_set_post_categories($entry['post_id'], $base_cat_id + $generic_n_cat_id + $specific_n_cat_id); 

however, when post assigned first 2 categories. using right method add these arrays together?

edit:

i got work doing following:

$cat_ids = array($base_cat_id['term_id'], $generic_a_cat_id['term_id'], $specific_a_cat_id['term_id']); wp_set_post_categories($entry['post_id'], $cat_ids); 

it's not pretty. found using array_merge same string id not work, overwrites values. union not work either can use union 2 arrays. please let me know if there better way!

use function array_merge(). arguments many arrays merging , returns arrays merged in 1 array, returns array.

like this:

wp_set_post_categories($entry['post_id'], array_merge($base_cat_id, $generic_n_cat_id, $specific_n_cat_id)); 

caveat: if arrays multilevel, might weird results. more info check out: http://php.net/manual/en/function.array-merge.php


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -