Skip to content

Add ability to search limited timeframe#52

Merged
pkevan merged 3 commits intomasterfrom
add-ability-to-search-limited-timeframe
Dec 16, 2016
Merged

Add ability to search limited timeframe#52
pkevan merged 3 commits intomasterfrom
add-ability-to-search-limited-timeframe

Conversation

@david-binda
Copy link
Copy Markdown
Contributor

@david-binda david-binda commented Dec 15, 2016

This PR is adding a new filter for filtering the default value of the date filter and is adding a support for arrays inside the $date_filters array, which in turn allows developers to provide advanced date filtering of the results.

Together with the zoninator_search_args filters, developers could limit the search, by default, to past 60 days only, making the queries on the backend more performant, than the default full table scan search.

Example implementation of default time filtering limited to past 60 days:

add_filter( 'zoninator_advanced_filter_date', function( $date_filters ) {
	return array_merge( (array) $date_filters, array(
		array(
			'value' => 'past60days',
			'label' => 'Past 60 days'
		)
	) );
} );

add_filter( 'zoninator_advanced_filter_date_default', function( $default ) {
	return 'past60days';
} );

add_filter( 'zoninator_search_args', function( $args ) {
	global $zoninator;
	$date = $zoninator->_get_get_var( 'date', '', 'striptags' );
	if ( 'past60days' === $date ) {
		$args['date_query'] = array(
			array(
				'after' => '-60 days'
			)
		);
	}
	return $args;
}, 10 );

This commit is adding `zoninator_advanced_filter_date_default` filter for filtering the default value of the date filter
By allowing developers to pass an array as a date filter, we give them ability to provide custom label and custom value of the field.

The custom value, not being parsed by `strtotime`, can be used for custom time limitations when processing the AJAX search requests
Since the code does not need to know how many matching posts are in the database, the no_found_rows should be set to true
Copy link
Copy Markdown
Member

@mjangda mjangda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@pkevan
Copy link
Copy Markdown
Contributor

pkevan commented Dec 16, 2016

Looks good

@pkevan pkevan merged commit 1dbc253 into master Dec 16, 2016
Copy link
Copy Markdown
Contributor

@pkevan pkevan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mjangda mjangda deleted the add-ability-to-search-limited-timeframe branch December 21, 2016 17:52
@GaryJones GaryJones added this to the 0.7 milestone Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants