I finally found a solution. For those who might also stumble on this.
What I had to do is to put ASC and DESC as option values for the date sorting. I read in the documentation that WordPress uses these values by default to sort data.
<select class="dropdown-class" name="order" id="sortbox">
<option value="DESC">Newest</option>
<option value="ASC">Oldest</option>
</select>
Then, create a variable that stores the search query values:
$sortedDate=$ _GET[ 'order']; //Either DESC or ASC
Finally, I had to sort the database query using the result from the search query:
$args=array( 'cat'=>6,
'meta_value' => $places,
'order'=> $sortedDate,
'paged'=>$paged, );
query_posts($args);
Full code:
–advanced-search.php
<?php
/**
* Template Name: Advanced Search
* Author: Atanas Yonkov
*/ ?>
<form class="post-filters" name="search" action="" method="get">
<select name="place">
<option value="" disabled selected> Place </option>
<?php $metakey='place' ; $places=$ wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) ); if ($places) { foreach ($places as $place) { echo "
<option value=\ "" . $place . "\">" . $place . "</option>"; } } ?>
</select>
<select class="dropdown-class" name="order" id="sortbox">
<option value="DESC">Newest</option>
<option value="ASC">Oldest</option>
</select>
<input type="submit" value="Search" />
</form>
<?php $places=$ _GET[ 'place'];
$sortedDate=$ _GET[ 'order'];
if ($places || $sortedDate) {
$paged=( get_query_var( 'paged')) ? get_query_var( 'paged') : 1;
$args=array( 'cat'=>6,
'meta_value' => $places,
'order'=> $sortedDate,
'paged'=>$paged, );
query_posts($args);
} else {
query_posts('cat=6&posts_per_page=5');
}
if ($places) { ?>
<h1>Search for: <?php echo $places; ?></h3>
<?php } else { ?>
<h3></h3>
<?php }
— category-6.php
<?php
/**
* The template for displaying programs
* Implements custom advanced search filter
*/
get_header();
//Call the advanced-search.php template
get_template_part( 'advanced-search', get_post_format()) ?>
<div class="content-area">
<?php if ( have_posts() ) : //Loop through posts ?>
<header class="archive-header">
<?php
the_archive_title( '<h1 class="archive-title">', '</h1>' );
the_archive_description( '<div class="archive-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</div><!-- .content-area -->
<?php wp_reset_query(); ?>
<?php
get_sidebar();
get_footer();
The final result is that I am able to sort post types from specific category based on two different criteria.