0

I've searched and found this and a few more. But I still couldn't get the selected name (not value as value is just a number). get_categories keeps returns an empty array.

Below is the code from the plugin that I'm modding.

$categories = apply_filters( 'acadp_admin_listing_form_categories_dropdown', '', $post->ID );

        if ( empty( $categories ) ) {
            $selected_category = count( $category ) ? $category[0] : -1;
            
            $args = array(
                'show_option_none' => '-- ' . esc_html__( 'Select category', 'advanced-classifieds-and-directory-pro' ) . ' --',
                'taxonomy'         => 'acadp_categories',
                'name'             => 'acadp_category',
                'orderby'          => 'name',
                'selected'         => (int) $selected_category,
                'hierarchical'     => true,
                'depth'            => 10,
                'show_count'       => false,
                'hide_empty'       => false,
                'echo'             => false,
            );
            
            if ( $disable_parent_categories ) {
                $args['walker'] = new ACADP_Walker_CategoryDropdown;
            }
            
            $categories = wp_dropdown_categories( $args );
        }

        echo $categories; 

1 Answer 1

0

I figured it out. To get the selected category, I don't need all the codes above. I just need the below.

$category = wp_get_object_terms( $post->ID, 'acadp_categories' );
$selected_category = $category[0]->name;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.