<?php 
/**
* Order and order by options
*
* @since Campoal 1.7.4
*/
if (!function_exists('conikal_sort_petition_options')) :
	function conikal_sort_petition_options($type = false) {
		$order_options = array(
		    'ASC'   => esc_html__('Ascending', 'campoal'),
		    'DESC'  => esc_html__('Descending', 'campoal'),
		);

		$orderby_options = array(
		    'name'          => esc_html__('Name', 'campoal'), 
		    'author'        => esc_html__('Author', 'campoal'),
		    'title'         => esc_html__('Title', 'campoal'),
		    'date'          => esc_html__('Date', 'campoal'),
		    'views'			=> esc_html__('Views', 'campoal'),
			'comment_count' => esc_html__('Comments', 'campoal'),
		);

		if (function_exists('conikal_register_petition_type')) {
			$orderby_options['supporters'] = esc_html__('Supporters', 'campoal');
		}

		if ($type == 'order') {
			return $order_options;
		} elseif ($type == 'orderby') {
			return $orderby_options;
		} else {
			$merge_options = array(
				'order' => $order_options,
				'orderby' => $orderby_options,
			);

			return $merge_options;
		}
	}
endif;


/**
* Change meta key ordering
*
* @since Campoal 1.7.4
*/
if (!function_exists('conikal_meta_key_ordering_filter')) :
	function conikal_meta_key_ordering_filter($orderby) {
		if ( $orderby == 'supporters' || $orderby == 'views') {
			$orderby = 'meta_value_num';
		}

		return $orderby;
	}
endif;

?>