Last active
December 19, 2025 13:22
-
-
Save mainiomooses/f77dac3091d5945d6e06395d8817c3d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if (is_single()) { | |
| if( has_term('', 'sijainti', $post->ID) ){ | |
| $sijainnit = wp_get_post_terms( $post->ID, 'sijainti' ); | |
| $target = $sijainnit[0]->term_id; | |
| if (in_array($target, $gifts_valid_locations)) { | |
| $mm_donation__gift_key = array_search($target, $gifts_valid_locations); | |
| return $gifts[$mm_donation__gift_key]; | |
| } | |
| $target_progenitor = $target; | |
| $target_ancestors = get_ancestors($target, 'sijainti'); | |
| foreach ($target_ancestors as $target_ancestor) { | |
| $term = get_term( $target_ancestor, 'sijainti' ); | |
| if ( ! $term->parent ) { | |
| $target_progenitor = $target_ancestor; | |
| } | |
| } | |
| $target_progenitor_children = get_term_children( $target_progenitor, 'sijainti' ); | |
| array_unshift($target_progenitor_children, $target_progenitor); // Insert progenitor to index 0 to prioritize it | |
| foreach ($target_progenitor_children as $valid) { | |
| if (in_array($valid, $gifts_valid_locations)) { | |
| $mm_donation__gift_key = array_search($valid, $gifts_valid_locations); | |
| return $gifts[$mm_donation__gift_key]; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment