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

Add ‘Include Sold STC’ checkbox

Video Guide: https://komododecks.com/recordings/gpgL0tlXx6yIMScbXPKK
// STEP 1: ADD TO functions.php
add_action('pre_get_posts', 'remove_sold_stc_by_default');
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;

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

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

	if (
		!isset($_REQUEST['include_sold_stc'])
	) {
                if (!is_array($tax_query)) { $tax_query = array(); }
		$tax_query[] = array(
			'taxonomy' => 'availability',
			'field' => 'term_id',
			'terms' => array(10, 14), // NOTE: change (10, 14) to the IDS of 'For Sale' and 'To Let'
			'operator' => '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['include_sold_stc'])) { unset($form_controls['include_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 div where you want the checkbox to appear inside the search-form.php:

<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? No 1 Yes

How can we help?