Documentation

Hey there, it looks like you've been redirected from designsandcode.com - as you can see we have a new home - read more

Action & Filter Reference

Actions

Update Cache for a Particular Post

Available since v2.0

Usage

do_action('search_filter_update_post_cache', 23);

Takes 1 parameters – Post ID

This allows you to manually update the cache for a particular post – replace 23 with the ID of your post.

Force S&F Pagination on non results pages

Available since v2.0

Usage

do_action('search_filter_setup_pagination', 96);

Takes 1 parameters – Search Form ID

This is generally not required but allows you to manually apply S&F pagination on typically non results pages.  Place this action just before your pagination code.

Query Posts

Available since v2.0

Usage

do_action('search_filter_query_posts', 96);

Takes 1 parameters – Search Form ID

This runs a Query Posts using the search form data and user’s selection in the search form.  It is only necessary for problematic themes when using either Archive or Post Type Archive Display Methods – it should be added to the top of the template used for displaying results.

Filters

Edit Query Arguments

Available since v2.0

Usage

function filter_function_name( $query_args, $sfid ) {
	
	//if search form ID = 225, the do something with this query
	if($sfid==225)
	{
		//modify $query_args here before returning it
		$query_args['somearg'] = 'newvalue';
	}
	
	return $query_args;
}
add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

Takes 2 parameters –

  • $query_args – an array of query arguments – this is the same as the `$args` variable that gets passed to WP_Query
  • $sfid – this is the numeric ID of the Search Form

Make sure to return $query_args after you have modified it as with all WP filters

Filter Input Object

Available since v2.1

Usage

function filter_function_name($input_object, $sfid)
{
	if($input_object['name']=='_my_field_name')
	{
		//udpate this field before rendering
	}
	
	return $input_object;
}
add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);

Takes 2 parameters –

  • $input_object – this is an object representing all the options available to a html input field – most options can be changed such as classes, options & defaults – see a full featured example here.
  • $sfid – this is the numeric ID of the Search Form

Modify URLs

Available since v2.2

** Note, altering the URLs may lead to unexpected results.  These filters are generally only available for doing things like changing the protocol, ie replacing `http` with `https` for example.

Usage

function filter_function_name( $url,  $sfid) {
  // Process URL here
  return $url;
}
add_filter( 'sf_results_url', 'filter_function_name', 10, 2 );

There are 3 kinds of URLs Search & Filter uses, each has their own filter name:

sf_results_url

This URL is used for most setups for various actions

sf_ajax_results_url

This URL is only used when using the Shortcode Display Method with Ajax enabled

sf_ajax_form_url

This URL is used to fetch the Search & Filter form when the option Update the Search Form on user interaction is enabled. It is only used for fetching a new copy of the Search Form