I am trying to filter posts with certain values and sort by the date field using ACF module. I have succeeded in filter with package and type. But when i added date sort, its not working. Please help me. Can we filter and sort simultaneously using ACF?
<?php
$package = $_GET['package'];
$type = $_GET['type'];
$sort = $_GET['sort'];
$filterquery = array('relation' => 'AND');
if (isset($package) && $package != "All")
{
$filterquery[] = array(
'key' => 'package',
'value' => $package,
'compare' => '='
);
}
if (isset($type) && $type != "All")
{
$filterquery[] = array(
'key' => 'type',
'value' => $type,
'compare' => '='
);
}
if (isset($sort))
{
$filterquery[] = array(
'meta_key' => 'sortdate', // name of custom field
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
}
else
{
$filterquery[] = array(
'meta_key' => 'sortdate', // name of custom field
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
}
$args = array(
'posts_per_page' => 6,
'cat' => '4',
'meta_query' => $filterquery,
);
$query = new WP_Query($args); ?>