Skip to content

Instantly share code, notes, and snippets.

@g-maclean
Created November 4, 2024 11:59
Show Gist options
  • Select an option

  • Save g-maclean/78d9edfe52754f4ac07f96d9946e2ecb to your computer and use it in GitHub Desktop.

Select an option

Save g-maclean/78d9edfe52754f4ac07f96d9946e2ecb to your computer and use it in GitHub Desktop.
Property Hive available-from custom field added as new dropdown in search
add_filter('propertyhive_search_form_fields_default', 'edit_default_property_search_form_fields', 99);
function edit_default_property_search_form_fields($fields)
{
$fields['available_from'] = array(
'type' => 'select',
'label' => __('Available From', 'propertyhive'),
'show_label' => true,
'before' => '<div class="control control-available_from">',
'options' => array(
'' => 'No Preference',
'available-now' => 'Available Now',
'available-2025' => 'Available 2025',
)
);
return $fields; // return the fields
}
add_filter('propertyhive_property_query_meta_query', 'filter_on_available_from', 10, 2);
function filter_on_available_from($meta_query, $ph_query)
{
if (
isset($_REQUEST['available_from']) && $_REQUEST['available_from'] != ''
) {
$available_from = ph_clean($_REQUEST['available_from']);
$meta_query[] = array(
'key' => '_available_from',
'value' => $available_from,
'compare' => '=',
);
}
return $meta_query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment