Display REP Search Form on Office Hero Banner of Malcolm Listings or Malcolm Central plugin.

This guide will help you customize the office hero banner on Malcolm Real Estate website using Malcolm Listings or Malcolm Central plugin by integrating a search form based on the selected form type.

1. Access Your Theme’s Functions File

  • To begin, log in to your WordPress admin dashboard.
  • Next, navigate to the “Appearance” menu and select “Theme Editor.”
  • In the right-hand panel, you’ll see a list of theme files. Find and click on the “functions.php” file associated with your currently active theme.

2. Insert the Provided Code

  • Once you’ve opened the “functions.php” file, scroll to the bottom or a convenient location for adding custom code.
  • This can also be done if you have installed code snippets plugin in your WordPress site like WPCode and Code Snippets to insert the code.
  • Copy and paste the following code snippet into the “functions.php” file:
// Add Office Hero Form Type Field
if( function_exists('\Launchpad\lp__add_field') && defined( 'REP__PREFIX' ) ) {
    Launchpad\lp__add_field( array(
		'id' => REP__PREFIX.'_office_details_c00_f001',
		'key' => 'hero_form_type',
		'label' => __( 'Hero Form Type', 'rep-malcolm' ),
		'type' => 'select',
		'choices' => array(
			'sellers' => 'For Sellers',
			'buyers' => 'For Buyers',
			'suburb_report' => 'Suburb Report',
		),
		'parent' => REP__PREFIX.'_office_details',
		'position' => 15,
	) );
}

// Remove default office hero banner buttons
add_filter('rep__office_hero_banner_buttons', function($buttons){
	return [];
});

// Render office hero form to office
add_action('rep__office_hero_banner_body', function(){ ?>
	<div class="lp-hero-form"><?php 
		$form_type = get_post_meta( get_the_ID(), 'hero_form_type', true ) ?: 'sellers';
		if($form_type == 'sellers'): 
			echo do_shortcode('[rep_search_form filter_popup="on" search_types="sell,sale,lease,sold"]');
		elseif($form_type == 'buyers'): 
			echo do_shortcode('[rep_search_form filter_popup="on" search_types="sale,lease,sold,sell"]'); 
		else: 
			echo do_shortcode('[rep_search_form filter_popup="on" search_types="suburb_report"]'); 
		endif; ?>
	</div><?php
});

Result

Added Hero Form Type Field on office details
Rendered search form for seller
The code will add a field, to allow selection of hero form type and render the corresponding search form based on the selected value.
This documentation provides a comprehensive guide for implementing and comprehending the provided code. You can further customize this code to adapt to your specific requirements. This flexibility allows you to tailor the code to various scenarios within your WordPress site.

The tutorial is only applicable to Malcolm Central and Malcolm Listings plugin. The old Malcolm Real Estate Plugin (a.k.a. Malcolm HQ) has this functionality by default.

3. Understanding the Code

The code has three parts:

  1. Adding an Option Field for Selecting the Form Type
    • Registers a new field in the office post type using lp__add_field.
    • Allows users to choose between “For Sellers,” “For Buyers,” or “Suburb Report” as the hero form type.
  2. Removing Default Office Hero Buttons
    • Uses the rep__office_hero_banner_buttons filter to remove any pre-existing buttons from the hero banner.
  3. Rendering the Search Form Based on the Selected Form Type
    • Hooks into rep__office_hero_banner_body to display the correct search form inside the office hero banner.
    • Determines the form type from the office post’s meta field hero_form_type.
    • Displays the appropriate search form using shortcodes:
      • “For Sellers” -> Displays search form for sell (property appraisal), sale, lease, and sold property search.
      • “For Buyers” -> Displays search form for sale, lease, sold, and sell (property appraisal) properties.
      • “Suburb Report” -> Displays a search form for suburb reports.

      4. Save the Changes

      After adding the code, click the “Update File” button to save your changes to the “functions.php” file.

      5. Testing

      To see the changes in action:

      1. Navigate to an office post in your WordPress admin.
      2. Select the desired “Hero Form Type” in the office details section.
      3. Visit the office page on your website.
      4. The selected search form should appear in the hero banner, replacing the default buttons.

      This customization enhances user experience by allowing different search forms based on office-specific preferences.