Skip to content

Instantly share code, notes, and snippets.

@g-maclean
g-maclean / snippet.php
Created December 4, 2024 08:57
PropertyHive - 301 redirect if marketing flag exists
add_action('template_redirect', function () {
if (is_singular('property')) {
global $post;
$terms = get_the_terms($post, "marketing_flag");
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
if ($term->term_id === 123) { //replace this with the marketing flag ID
wp_redirect(home_url('/some-url-to-redirect-to/'), 301); //replace this with desired destination
exit;
}
@g-maclean
g-maclean / snippet.php
Last active December 10, 2024 17:37
PropertyHive - StuRents import room viewing URL and add as action
add_action( "propertyhive_sturents_property_imported", "import_book_a_tour", 10, 2 );
function import_book_a_tour( $post_id, $property ) {
// sturents uses a viewing link for each room, here we're just using the first one
if(isset($property["available"][0]["viewing_url"])){
update_post_meta($post_id, "_book_a_tour_url", $property["available"][0]["viewing_url"]);
}
}
add_filter( 'propertyhive_single_property_actions', 'add_book_a_tour_action' );
function add_book_a_tour_action( $actions )
@g-maclean
g-maclean / snippet.php
Created December 9, 2024 07:34
PropertyHive - Add extra thumbnail size to PH Elementor Image Widget
add_action('propertyhive_elementor_widget_property_image_controls', 'add_extra_thumbnail_sizes_to_widget', 10, 2);
function add_extra_thumbnail_sizes_to_widget($widget){
$widget->update_control(
'image_size',
[
'label' => __( 'Image Size', 'propertyhive' ),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => [
'thumbnail' => __( 'Thumbnail', 'propertyhive' ),
'medium' => __( 'Medium', 'propertyhive' ),
@g-maclean
g-maclean / snippet.php
Created December 9, 2024 14:06
PropertyHive - Export RM new_home flag
add_filter('property_hive_export_request_data', 'new_home_property_on_export', 10, 2);
function new_home_property_on_export($request_data, $post_id)
{
$is_new_home = false;
$terms = wp_get_post_terms($post_id, 'marketing_flag');
foreach ($terms as $term) {
if ($term->term_id == 123) { // replace this with the term id of the new home flag
$is_new_home = true;
@g-maclean
g-maclean / snippet.php
Last active December 16, 2024 06:52
PropertyHive - remove Sold and Let from search results
add_action('pre_get_posts', 'remove_sold_and_let_from_search');
function remove_sold_and_let_from_search($q)
{
if ( is_admin() || !$q->is_main_query() || !$q->is_archive() || ($q->get( 'post_type' ) != "property") ){
return;
}
$tax_query = $q->get('tax_query');
$tax_query[] = array(
@g-maclean
g-maclean / snippet.php
Last active December 16, 2024 15:48
Property Hive - SEO search URLs WITH location names instead of IDs
add_filter( 'query_vars', 'propertyhive_register_query_vars' );
function propertyhive_register_query_vars( $vars )
{
$vars[] = 'property_search_criteria';
return $vars;
}
add_action( 'init', 'propertyhive_add_rewrite_rules' );
function propertyhive_add_rewrite_rules()
@g-maclean
g-maclean / snippet.php
Created December 23, 2024 13:37
PropertyHive - Turn on Users menu item for Editors in PH-only mode
// install User Role Editor plugin and set list_users for the Editor role
add_filter('propertyhive_remove_menu_item_in_crm_only_mode', 'turn_on_posts', 10, 2);
function turn_on_posts($show, $menu_item)
{
if ( isset($menu_item[2]) && $menu_item[2] == 'users.php' )
{
return false;
}
return $show;
@g-maclean
g-maclean / snippet.php
Created January 5, 2025 15:22
propertyhive - rest endpoint for getting slug from ref number
/**
* rest api ref lookup
*/
// Register the REST API route
add_action('rest_api_init', function () {
register_rest_route('property/v1', '/lookup', [
'methods' => 'GET',
'callback' => 'get_property_slug_by_ref',
'args' => [
'ref' => [
@g-maclean
g-maclean / snippet.pho
Created January 16, 2025 19:23
PropertyHive - Sort properties by address in admin area
function enable_address_sorting_for_properties($query) {
if (is_admin() && $query->is_main_query() && $query->get('post_type') === 'property') {
if (isset($_GET['orderby']) && $_GET['orderby'] === 'address') {
$query->set('orderby', 'title');
$query->set('order', isset($_GET['order']) ? $_GET['order'] : 'ASC');
}
}
}
add_action('pre_get_posts', 'enable_address_sorting_for_properties', 99);
@g-maclean
g-maclean / snippet.php
Last active January 29, 2025 19:29
PropertyHive - Reapit force use standard ID instead of alternateID
add_action( "propertyhive_property_imported_reapit_foundations_json", 'force_main_id_import', 10, 2 );
function force_main_id_import( $post_id, $property )
{
if ( isset($property['id']) && !empty($property['id']) )
{
update_post_meta( $post_id, '_reference_number', $property['id'] );
}
}