<?php 
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $wp;
global $campoal_options;
$sortby_default = isset($campoal_options['conikal_sortby_default_field']) ? $campoal_options['conikal_sortby_default_field'] : 'date';
$sorder_default = isset($campoal_options['conikal_order_default_field']) ? $campoal_options['conikal_order_default_field'] : 'DESC';

// get sorting options 
$order_options = conikal_sort_petition_options('order');
$orderby_options = conikal_sort_petition_options('orderby');

/*
if(is_page_template('all-give-forms.php') || is_tax('give_forms_category') || is_tax('give_forms_tag')) {
    unset($orderby_options['supporters']);
} */

$order      = isset($_GET['order']) && !empty($_GET['order']) ? sanitize_text_field($_GET['order']) : $sorder_default;
$orderby    = isset($_GET['orderby']) && !empty($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : $sortby_default;
?>

<!-- start order button -->
<div class="ui dropdown item petition-orderby">
    <?php echo esc_html(!empty($orderby) ? $orderby_options[$orderby] : __('Sort by', 'campoal')) ?>
    <i class="dropdown icon"></i>
    <div class="menu">
        <?php foreach ($orderby_options as $key => $value) { ?>
            <a class="item" href="<?php echo add_query_arg( array_merge($_GET, array('orderby' => $key)), home_url( $wp->request ) ); ?>"><?php echo esc_html($value) ?></a>
        <?php } ?>
    </div>
</div>
<div class="ui dropdown item petition-order">
    <?php echo esc_html(!empty($order) ? $order_options[$order] : __('Order', 'campoal')) ?>
    <i class="dropdown icon"></i>
    <div class="menu">
        <?php foreach ($order_options as $key => $value) { ?>
            <a class="item" href="<?php echo add_query_arg( array_merge($_GET, array('order' => $key)), home_url( $wp->request ) ); ?>"><?php echo esc_html($value) ?></a>
        <?php } ?>
    </div>
</div>
<!-- end order button -->