1. Docs
  2. Developer Guide
  3. Miscellaneous and Snippets
  4. Add ‘Include Sold STC’ checkbox

Add ‘Include Sold STC’ checkbox

// STEP 1: ADD TO functions.php
// NOTE: change (10, 14) to the IDS of 'For Sale' and 'To Let'
add_action('pre_get_posts', 'remove_sold_stc_by_default', 99);
function remove_sold_stc_by_default($q) 
{
    if (is_admin())
        return;

	if (!$q->is_main_query())
		return;

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

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

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

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

// 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-include-sold-stc"><label><input type="checkbox" value="1" name="include_sold_stc"<?php if (isset($_REQUEST['include_sold_stc'])) { echo ' checked'; } ?>> Include Under Offer, Sold STC</label></div>
Was this article helpful to you? Yes No