Blog

Multiplying a Shortcode with PL_FILTER

By Matt Williams

Developers

A couple days ago, a partner asked me how many shortcodes do sites typically have. The reason he asked was that he needed to create 30 different city listings pages and didn’t want to have to create 30 sets of Search Form and Search Listings shortcodes. Luckily I was able to tell him he could do all 30 with a single set of those shortcodes, rather than 30. It all comes down to applying pl_filters. To learn more, watch the video, or read on below.

So the secret here is something that looks like this:


[pl_filter group='location' filter='locality' value='Boston']

This was all I had to add to my shortcode to get it show Boston listings. OK, let me step back a bit and explain what I mean.

Go and create a new Search Listings shortcode. Set it up just the way you want. In the video, I set it to only look at properties between 300K and 1 million dollars. Then I also added a filter for the City of Boston. The reason I did that was to figure out the filter statement. So scroll up to the top of this window and notice that there is a long form version of the shortcode.

In my shortcode, this looks like:

[search_listings width=’250′ height=’250′ sort_by_options=’cur_data.baths,cur_data.beds,location.locality, cur_data.price,cur_data.sqft,location.postal’ sort_by=’cur_data.price’ sort_type=’desc’ query_limit=’10’] [pl_filter group=’metadata’ filter=’min_price’ value=’300000′] [pl_filter group=’metadata’ filter=’max_price’ value=’1000000′] [pl_filter group=’location’ filter=’locality’ value=’Bolton’] [/search_listings]

In the middle of all of that is my secret pl_filter location locality block. I copied that and saved it for later. Now remove the city filter and save the shortcode. Copy the shortcode for the Search Listings and paste it onto the page you are going to add. Now paste the pl_filter block from above and close out the Search_Listings shortcode. The complete shortcode looks like this:


[search_form id='509']
[search_listings id='510']
[pl_filter group='location' filter='locality' value='Boston']
[/search_listings]

Now if this doesn’t seem to work and you have a search form on the same page, make sure the search form doesn’t include dropdowns for the values you set. So I had to modify my search form to not include anything related to price or city.

If anything here is a bit confusing, watch the video, or leave a question in the comments below.

Comments

Get our Newsletter
Follow Placester