Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend sorting order of Team Members

I'm using Business Lounge theme by RT themes with Elementor.

Wordpress version is current (5.2.1)

On the team page (Demo: https://businesslounge-demo.rtthemes.com/our-team/) there is a list of cards of team members. I want to change the order of the team members to an option that is not currently selectable.

The team member list is done with a shortcode [staff_box]

In Elementor edit mode I looks like this:
enter image description here

Edit:

The edit form is defined in
wp-content/plugins/businesslounge-extensions/inc/elementor-addons/staff.php

<?php
namespace Elementor;
// ...
class Widget_RT_Staff extends Widget_Base {
  // ...
  protected function _register_controls() {
    // ...
    $this->add_control(
      'list_orderby',
        [
          'label'     => esc_html_x( 'List Order By', 'Admin Panel','businesslounge' ),
          'description' => esc_html_x('Sorts the posts by this parameter', 'Admin Panel','businesslounge' ),    
          'type'      =>  Controls_Manager::SELECT,
          'default'    =>  "date",
          "options"    => array(
            'date' => esc_html_x('Date',"Admin Panel","businesslounge"),
            'author' => esc_html_x('Author',"Admin Panel","businesslounge"),
            'title' => esc_html_x('Title',"Admin Panel","businesslounge"),
            'modified' => esc_html_x('Modified',"Admin Panel","businesslounge"),
            'ID' => esc_html_x('ID',"Admin Panel","businesslounge"),
            'rand' => esc_html_x('Randomized',"Admin Panel","businesslounge"),                                  
          )
        ]
      );     
      // ...
  }
  // ...
}

Plugin::instance()->widgets_manager->register_widget_type( new Widget_RT_Staff() );
The edit form is defined in `wp-content/plugins/businesslounge-extensions/inc/editor/staff_box.php` like so
<?php
vc_map(
    array(
        'base'        => 'staff_box',
        'name'        => _x( 'Team', 'Admin Panel','businesslounge' ),
        'icon'        => 'rt_theme rt_team',
        'category'    => array(_x( 'Content', 'Admin Panel','businesslounge' ), _x( 'Theme Addons', 'Admin Panel','businesslounge' )),
        'description' => _x( 'Displays team members', 'Admin Panel','businesslounge' ),
        'params'      => array(
// ...    
          array(
            'param_name'  => 'list_orderby',
            'heading'     => _x( 'List Order By', 'Admin Panel','businesslounge' ),
            "description" => _x("Sorts the posts by this parameter",'Admin Panel','businesslounge'),
            'type'        => 'dropdown',
            "value"       => array(
                                _x('Date','Admin Panel','businesslounge') => 'date',
                                _x('Author','Admin Panel','businesslounge') => 'author',
                                _x('Title','Admin Panel','businesslounge') => 'title',
                                _x('Modified','Admin Panel','businesslounge') => 'modified',
                                _x('ID','Admin Panel','businesslounge') => 'ID',
                                _x('Randomized','Admin Panel','businesslounge') => 'rand',
                            ),
            'save_always' => true
        ),
// ...

The output is defined in
wp-content/plugins/businesslounge-extensions/inc/shortcodes/staff_box.php

like so:

<?php
function rt_staff( $atts, $content = null ) { 
// ...

    //defaults
    extract(shortcode_atts(array(  
        "id"           => 'staff-'.rand(100000, 1000000), 
        "class"        => "", 
        "list_layout"  => "1/1", 
        "list_orderby" => "date",
        "list_order"   => "DESC",
        "ids"          => array(),
        "box_style"    => ""        
    ), $atts));

// ...

    //general query
    $args=array( 
        'post_status'    => 'publish',
        'post_type'      => 'staff',
        'orderby'        => $list_orderby,
        'order'          => $list_order,
        'showposts'      => 1000                                                            
    );
// ...
    $theQuery = query_posts($args);
// ...

What I want to do: Add an option 'post_name' to the select box so that I can sort the team by a different field. I want to add 'Post name' => 'post_name',

How can I do this without changing the original source code?
I already have the child theme of business_lounge theme activated.
Do I need a custom extension for this?

like image 749
yunzen Avatar asked Nov 06 '22 17:11

yunzen


1 Answers

You'd have to modify the original code. You can't override the function unless the author applied a filter to the value returned, or used an action.

As gael notes in his answer, you can soften the blow of losing changes on updates by copying the original code into your child theme's functions.php then renaming the function - for e.g. to my_rt_staff() before adding in your modifications.

You would however still need to call the my_rt_staff() in the plugin instead of rt_stuff and you would have to make this change whenever the plugin was updated, but you wouldn't lose your code.

(Perhaps you could change the "list_orderby" => "date" in the default shortcode attributes to "list_orderby" => "post_name", as default in your modified my_rt_staff() method so it orders by name as default instead of date)

However, this does not help much in your specific circumstance, as the ideal modification you need to make is to the control itself, on the _register_controls() method in the Widget_RT_Staff class. You can override this by extending Widget_RT_Staff but you would still need to call your new class which results in you modifying the plugin code.

Without seeing how the Widget_RT_Staff class affects the shortocde, I can't be certain this would work, but based on the rt_staff() method, if you use the shortcode as [staff_box orderby="post_name"] you may get your intended result without having to touch any code.

like image 198
Tonyeli Tay Avatar answered Nov 14 '22 10:11

Tonyeli Tay