Skip to content
Advertisement

Wrong author ID output from elementor module

I create a module for elementor. I need to display the author name, choosen from the elementor admin control. I have 4 administrator. They show up correctly on control panel:

  1. admin (ID=0.)
  2. Jhon Doe (ID=1.)
  3. Jeane Doe (ID=3.)
  4. Mary Doe (ID=5.)

The code for Elementor admin panel:

 <php 
 //Get all author
 $blogusers = get_users('blog_id=1&orderby=nicename&role=Administrator');
 foreach ($blogusers as $user) {

$author_list[] = $user->user_nicename; }

        $this->add_control(
            'my_authorname',
                [
                    'label'       => __( 'From AUTHOR', 'my_authorname-for-elementor' ),
                    'type' => Controls_Manager::SELECT, 
                    'options' => $author_list,
                    'default' => 'admin'
                ]
        ); ?>   
    

When I choose Jeane Doe from Elementor control admin, the output on the frontpage display the wrong author ID (1, and Jeane Doe ID is 3). Not the author name which I need.

The code for the output:

 <?php echo $settings['my_authorname'];  ?>

Really appreciate for any helps.

Advertisement

Answer

Change

$author_list[] = $user->user_nicename;

to

$author_list[$user->ID] = $user->user_nicename;

See: Arguments section here: https://developers.elementor.com/elementor-controls/select-control/

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement