<?php
/**
 * Ordering
 *
 * This template can be overridden by copying it to yourtheme/wp-real-estate/agency-loop/orderby.php.
 */
if (!defined('ABSPATH')) {
	exit; // Exit if accessed directly
}

$contextual_query = wre_get_contextual_query();
if ( 1 === $contextual_query->found_posts ) {
	return;
}

$orderby = isset($_GET['wre-orderby']) ? $_GET['wre-orderby'] : 'date';
$orderby_options = apply_filters('wre_agency_orderby', array(
	'date' => __('Recently Added', 'wp-real-estate'),
	'title' => __('Title (Asc)', 'wp-real-estate'),
	'title-desc' => __('Title (Desc)', 'wp-real-estate')
		));
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
?>
<form class="wre-ordering" method="get">
	<div class="wre-select-wrap">
		<select name="wre-orderby" class="agencies-orderby">
			<?php foreach ($orderby_options as $id => $name) : ?>
				<option value="<?php echo esc_attr($id); ?>" <?php selected($orderby, $id); ?>><?php echo esc_html($name); ?></option>
			<?php endforeach; ?>
		</select>
	</div>
	<input type="hidden" id="paged" name="paged" value="<?php echo esc_attr( $paged ); ?>" />
</form>