Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

what I want is that I have a special taxonomy and get_terms does not work without it being loaded, naturally the only way I can get it is to hook up to "init". But when this is the case, I will have to repeat this. I do not want this.

As you can see in the code below, I am doing the operation in init and trying to transfer it to "$ new_array". How can I do it?

    protected function get_reactions()
    {
        $new_array = array();
        
        add_action( 'init', function() use ( &$new_array ) {
            $reactions = get_terms( array(
                'taxonomy' => 'bp_reaction',
                'hide_empty' => false
            ));
    
            foreach ( $reactions as $value ) {
                $priority = get_option( 'taxonomy_'.$value->term_id.'_priority' );
                $image    = get_option( 'taxonomy_'.$value->term_id.'_image' );
                $new_array[$priority] = (object) array(
                    'id'       => $value->term_id,
                    'priority' => $priority,
                    'slug'     => $value->slug,
                    'name'     => $value->name,
                    'image'    => $image
                );
            }
        }, 9 );

        // Sort from largest to small
        krsort( $new_array );

        return $new_array;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
112 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...