1. Home
  2. Docs
  3. Developer Guide
  4. Displaying Sold and Let Properties

Displaying Sold and Let Properties

It's common on property sites to see a page displaying recently sold or let properties as a way for the agent to showcase the properties they've dealt with successfully in the past.

The tricky thing when it comes to displaying these on the website using Property Hive is that these properties are likely not on the market and therefore won't be included anywhere by default as only on market properties are shown on the search page and shortcodes.

In this guide we'll look at how you can show sold or let properties via the search results page, or via a shortcode.

Before we begin...

We'll be identifying which sold/let properties to display using Marketing Flags.
We could use the 'Availability' field and look for properties that are sold or let, however it's likely you might want to control which sold/let properties are shown over time so by using the marketing flags we can control this.

When you install Property Hive it does comes out of the box with some marketing flags that will assist us here: 'Recently Sold' and 'Recently Let'. If you don't have these options available (or have deleted them previously) you can configure these marketing flags under 'Property Hive > Settings > Custom Fields > Marketing Flags'. Once you've got your marketing flags configured be sure to make note of the ID's of the flags:

Whether you have two separate marketing flags to handle sales vs lettings, or just one (maybe called something like 'Recently Sold / Let') is up to you.

Displaying Them On The Search Results Page

If we want to use the main search results page to display these properties the first thing we can do is append the URL with '&marketing_flag=X', so it might look something like so:


We still have the issue of only on market properties showing by default so the above still wouldn't show any properties. Next we need to add the below code to our theme's functions.php file:

add_action( 'pre_get_posts', 'include_off_market' );
function include_off_market( $q )
    if ( is_admin() )

    if ( ! $q->is_main_query() )

    if  ( ! $q->is_post_type_archive( 'property' ) && ! $q->is_tax( get_object_taxonomies( 'property' ) ) )
// Replace ID '123' below with your ID found in Settings > Custom Fields > Marketing Flags
    if ( isset($_GET['marketing_flag']) && $_GET['marketing_flag'] == 123 )

        // we're filtering by sold properties

        $meta_query = $q->meta_query;

        $new_meta_query = array();
        foreach ( $meta_query as $meta_query_part )
            if ( isset($meta_query_part['key']) && $meta_query_part['key'] == '_on_market' )
                // we don't want this part so do nothing
                $new_meta_query[] = $meta_query_part;

        $q->set('meta_query', $new_meta_query);

When visiting the above URL you should now see the properties with the relevant marketing flags selected, regardless of the 'On market' box is ticked or not.

Displaying Them Using Shortcodes

If wanting to display these sold/let properties using a shortcode you might opt for something like so:

[properties department="residential-sales" marketing_flag_id="{sold-marketing-flag-id}"]

Simply using the above shortcode and adding the following to your theme's functions.php should ensure this works:

add_filter( 'propertyhive_properties_query', 'include_off_market_shortcode', 10, 2 );
function include_off_market_shortcode( $args, $atts )
//  Replace '123' with your ID found in Settings > Custom Fields > Marketing Flags    
if ( isset($atts['marketing_flag_id']) && $atts['marketing_flag_id'] == '123' )

        unset($args['meta_query'][0]); // remove 'on market' part of the meta query
    return $args;