1. Home
  2. Docs
  3. Developer Guide
  4. Miscellaneous and Snippet...
  5. Add ‘Exclude Sold STC’ checkbox

Add ‘Exclude Sold STC’ checkbox

// STEP 1: ADD TO functions.php
// NOTE: change (10, 14) to the IDS of 'Sold STC' and 'Let Agreed', and all other statuses you wish to exclude
add_action('pre_get_posts', 'remove_sold_stc_when_ticked');
function remove_sold_stc_when_ticked($q) 
{
    if (is_admin())
        return;

	if (!$q->is_post_type_archive('property') && !$q->is_tax(get_object_taxonomies('property')))
		return;

	if (isset($_GET['shortlisted']))
		return;

    $tax_query = $q->get('tax_query');

	if (
		isset($_REQUEST['exclude_sold_stc'])
	) {
                if (!is_array($tax_query)) { $tax_query = array(); }
		$tax_query[] = array(
			'taxonomy' => 'availability',
			'field' => 'term_id',
			'terms' => array(10, 14),
			'operator' => 'NOT IN'
		);
	}

    $q->set('tax_query', $tax_query);
}

add_filter( 'propertyhive_search_form_fields_after', 'remove_sold_stc_hidden', 10, 1 );
function remove_sold_stc_hidden($form_controls)
{
    if (isset($form_controls['exclude_sold_stc'])) { unset($form_controls['exclude_sold_stc']); }
    return $form_controls;
}

// STEP 2:
// Copy: /wp-content/plugins/propertyhive/templates/global/search-form.php
// To: /wp-content/themes/{your-theme-name}/propertyhive/global/search-form.php
// Include the following where you want the checkbox to appear

<div class="control control-exclude-sold-stc"><label><input type="checkbox" value="1" name="exclude_sold_stc"<?php if (isset($_REQUEST['exclude_sold_stc'])) { echo ' checked'; } ?>> Exclude Under Offer, Sold STC</label></div>
Was this article helpful to you? No Yes

How can we help?