Profisearchform 1.74 will come soon!

The next version of my plugin will be out soon. It will contain some bug fixes in the order-by-field but the most interesting changes will be for plugin developers, who want to extend the functionality of Profisearchform and deliver additional plugins:

Server side

As you already know, the plugin always delivers some filter hooks for you, where you can hook in with your own plugin. There will be some additional filter, to enable you to hook even better into the plugin. One of this hooks is for example sf-all-data. This filter is executed after a search is finished and just the moment before it will be delivered. This filter passes all data, which is usually send via JSON. So, you can alter this data using the sf-all-data filter. You will receive an array like this:

array(
	"post" 		=> array(),
	"result" 	=> array(),
	"head"		=> "",
	"nav"		=> array()
	
);

The post array contains the information of the search filter. The result array contains the single list elements, with the results. The head string contains the string “XX posts out of YY posts were found” and the nav array will contain the navigation list elements.

Furthermore, the single result list element will contain an additional attribute data-postID, which contains the ID of the post.

Client Side

But action hooks are always on the server-side. To give you even more abilities to write more complex plugins, which work together with Profisearchform, we have now defined Javascript Events which will enable you to hook into our plugin on the server-side.

One example: The “sfLoadEvent”

If a search is executed and the results are displayed, this event will be triggered in Javascript. You will be able to add an event listener, which will enable you to act every time, the results are displayed. So, for example, lets say, you want to display Profisearchform in masonry style and you are using a Javascript framework in order to do so. With this event, you will be able to apply the masonry framework every time the new results are loaded.

A basic script using this event:

var element = document.getElementsByClassName( 'sf-wrapper' );
element = element[0];
if(element.addEventListener){
	element.addEventListener('sfLoadEvent', function( event ){
		alert( 'Results loaded.' );
		console.log( event.data );
	}, false); 
} else if (element.attachEvent){
	element.attachEvent('sfLoadEvent', function( event ){
		alert( Results loaded.' );
		console.log( event.data );
	});
}

As you can see, this event is attached to div.sf-wrapper. So to listen to this event, you have to add the EventListener to this element. the event itself will deliver you a data object, which contains the array, which is delivered by the plugin via Ajax as well as the field values, which are used.

console.log( event.data ); will result in

	{
		"fields": 	{
					"1":value
					"2":value
					...
					"search-id":(string)
				}
		"data":		{
					//The array mentioned above
				}
	}

With these changes in 1.74 the plugin will enable you to fully customize and extend the plugins functionality to your needs. I hope, you like it.

The following two tabs change content below.
Seine erste Webseite hat David Remer 1998 in HTML verfasst. Wenig später war er fasziniert von DHTML und JavaScript. Heute konzentriert sich vor allem auf das Entwickeln von WordPress Themes und Plugins für Inpsyde. Außerdem hat er das Buch "WordPress für Entwickler" verfasst.

Latest posts by David Remer (see all)