You appear to be a bot. Output may be restricted
Description
Update the taxonomies for the post
Usage
oik_clone_lazy_update_taxonomies( $post, $target );
Parameters
- $post
- ( array ) required – the source post object
- $target
- ( ID ) required – the ID of the target post The source post may send an array like this
[post_taxonomies] => stdClass Object ( [required_version] => Array ( [0] => stdClass Object ( [term_id] => 347 [name] => 4.0 [slug] => 4-0 [term_group] => 0 [term_taxonomy_id] => 381 [taxonomy] => required_version [description] => [parent] => 0 [count] => 2 [filter] => raw ) ) [compatible_up_to] => Array ( [0] => stdClass Object ( [term_id] => 317 [name] => 4.0 [slug] => 4-0 [term_group] => 0 [term_taxonomy_id] => 349 [taxonomy] => compatible_up_to [description] => [parent] => 0 [count] => 38 [filter] => raw ) [1] => stdClass Object ( [term_id] => 341 [name] => 4.0.1 [slug] => 4-0-1 [term_group] => 0 [term_taxonomy_id] => 375 [taxonomy] => compatible_up_to [description] => [parent] => 317 [count] => 16 [filter] => raw ) [2] => stdClass Object ( [term_id] => 345 [name] => 4.1 [slug] => 4-1 [term_group] => 0 [term_taxonomy_id] => 379 [taxonomy] => compatible_up_to [description] => [parent] => 0 [count] => 15 [filter] => raw ) [3] => stdClass Object ( [term_id] => 348 [name] => 4.1.1 [slug] => 4-1-1 [term_group] => 0 [term_taxonomy_id] => 382 [taxonomy] => compatible_up_to [description] => [parent] => 345 [count] => 3 [filter] => raw ) ) )
The target post may have an array like this[required_version] => Array ( [0] => stdClass Object ( [term_id] => 159 [name] => 3.9 [slug] => 3-9 [term_group] => 0 [term_taxonomy_id] => 230 [taxonomy] => required_version [description] => [parent] => 0 [count] => 17 [filter] => raw ) ) [compatible_up_to] => Array ( [0] => stdClass Object ( [term_id] => 222 [name] => 4.0 [slug] => 4-0 [term_group] => 0 [term_taxonomy_id] => 283 [taxonomy] => compatible_up_to [description] => [parent] => 0 [count] => 4 [filter] => raw ) )
We need to reconcile the target's taxonomies with the source'sSource taxonomy Target taxonomy Processing x – Ignore this source taxonomy x x Process the terms in this taxonomy There will be a top level in the $taxonomies arrays for each registered taxonomy. In the event of a mismatch at this level we do nothing. The Compare function may help us find mismatches like this.– x Ignore this target taxonomy
Returns
voidSource
File name: oik-clone/admin/oik-clone-taxonomies.phpLines:
1 to 18 of 18
function oik_clone_lazy_update_taxonomies( $post, $target ) { $source_taxonomies = $post->post_taxonomies; $target_taxonomies = oik_clone_load_taxonomies( $target, $post->post_type ); bw_trace2( $target_taxonomies, "target_taxonomies" ); foreach ( $source_taxonomies as $source_taxonomy => $source_terms ) { $target_terms = bw_array_get( $target_taxonomies, $source_taxonomy, null ) ; bw_trace2( $target_terms, "target_terms", false ); bw_trace2( $source_terms, "source_terms", false ); if ( $target_terms !== null ) { oik_clone_lazy_update_taxonomy_terms( $target, (array) $source_terms, $target_terms ); } else { p( "Source taxonomy missing from target: $source_taxonomy" ); gobang(); } } }View on GitHub