I have a Custom Post Type called 'properties', and have set up an Archive page to display posts within that category.
Essentially, the Archive page needs to contain 3 different query types; the first to display search results of posts within the CPT, the second to make results sortable (queried through a drop-down menu that interrogates Custom Field meta values), and the third to display all posts within the CPT.
I'm not sure how to structure the queries and loops though - all the queries work individually, but I'm struggling how to set up the If/Else statements to make them work within one archive page, so would be grateful for any advice you might have!
Query 1: Search Results
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'properties',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'property_size',
'value' => $_GET['size'],
'compare' => '>='
),
array(
'key' => 'property_rent',
'value' => $_GET['budget-from'],
'compare' => '>=',
'type' => 'NUMERIC'
),
array(
'key' => 'property_rent',
'value' => $_GET['budget-to'],
'compare' => '<=',
'type' => 'NUMERIC'
)
),
'paged' => $paged
);
$query = new WP_Query( $args );
Query 2: Sortable Posts within CPT
if($_POST['square-sort-select'] == 0):
$select = $_POST['square-sort-select'];
$query = new WP_Query(array(
'post_type'=> 'properties',
'post_status' => 'publish',
'meta_key' => 'property_rent',
'orderby' => 'property_rent',
'order' => DESC
));
; elseif($_POST['square-sort-select'] == 1):
$select = $_POST['square-sort-select'];
$query = new WP_Query(array(
'post_type'=> 'properties',
'post_status' => 'publish',
'meta_key' => 'property_rent',
'orderby' => 'property_rent',
'order' => ASC
));
; elseif($_POST['square-sort-select'] == 2):
$select = $_POST['square-sort-select'];
$query = new WP_Query(array(
'post_type'=> 'properties',
'post_status' => 'publish',
'order' => DESC
));
Query 3: All Posts within CPT
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query();
$query->query('post_type=properties&posts_per_page=6&paged='.$paged);