How can I order the Fundraisers List Widget

I want the Fundraisers List Widget to be order alphabetically.

How can I do that, even if I need to change de code?

Regards

Rui Oliveira

  • Ash

    Hello Rui

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    Please go to /wp-content/plugins/fundraising/lib/widgets/widget.fundraiser_list.php

    Replace the widget function with the following code:

    function widget( $args, $instance ) {
    		// Widget output
    		$instance['numberposts'] = (isset($instance['numberposts']) && is_numeric($instance['numberposts'])) ? $instance['numberposts'] : -1;
    
    		$content = $args['before_widget'];
    		$content .= $args['before_title'] . esc_attr($instance['title']) . $args['after_title'];
    		$query = array(
    			'numberposts' => $instance['numberposts'],
    			'post_type' => 'funder',
    			'post_status' => 'publish'
    		);
    		$query = get_posts($query);
    		$data = array();
    		$i = 0;
    		foreach($query as $val) {
    			$data[$i]['link'] = get_post_permalink($funder->ID);
    			$data[$i++]['title'] = $val->post_title;
    		}
    		$this->aasort($data, 'title');
    
    		$content .= '<ul class="wdf_featured_fundraisers">';
    		foreach($data as $val) {
    			$content .= '<li><a href="'.$val['link'].'">'.$val['title'].'</a></li>';
    		}
    		$content .= '</ul>';
    		$content .= $args['after_widget'];
    		echo $content;
    	}

    Also add this function in the class:

    function aasort (&$array, $key) {
    		$sorter=array();
    		$ret=array();
    		reset($array);
    		foreach ($array as $ii => $va) {
    		    $sorter[$ii]=$va[$key];
    		}
    		asort($sorter);
    		foreach ($sorter as $ii => $va) {
    		    $ret[$ii]=$array[$ii];
    		}
    		$array=$ret;
    	    }

    Please let me know if it works for you :slight_smile:

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.