FacetWP Time Since facet typeThe Time Since facet type is used to filter posts by date / time since a specified interval.

Available options

Name Description
Data Source A date field, for example “Post Date”, “Post Modified”. Or a custom field in YYYY-MM-DD format.
Default label Change the default “Any” label. The label is optional: leave it blank to remove the “Any” option. Note: this label is translatable with the facetwp_i18n hook.
Choices The choices to display (one per line), consisting of a label and a format, separated by a “|”: label | format. Some examples:

Past Day | -1 day Past 7 Days | -7 days Past 30 Days | -30 days Past 90 Days | -90 days Past Year | -1 year Next 7 Days | +7 days Today | today Tomorrow | tomorrow Yesterday | yesterday

The formatter is based on PHP’s strtotime function. See the available relative date-time formats.

The choices labels are translatable with the facetwp_i18n hook.

Using custom ranges

Let’s say you wanted to add a choice to filter by Older than 1 year.

First, add a new row into the “Choices” box:

Older than 1 year | over-1-year

As you can see over-1-year is the custom formatting token. Since PHP won’t know how to automatically parse it, a hook is needed to set the date range manually:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter( 'facetwp_time_since_date_range', function( $range, $format ) { if ( 'over-1-year' == $format ) { $dt1 = new \DateTime( '1970-01-01' ); $dt2 = new \DateTime( '-1 year' ); $range['lower'] = $dt1->format( 'Y-m-d' ); $range['upper'] = $dt2->format( 'Y-m-d' ); } return $range; }, 10, 2);

Hide counts

To hide the counts, use any of the following styles, depending on which facet (types) you want to target:

How to use custom CSS?

CSS code can be placed in your (child) theme's style.css file. Alternatively, you can add it manually between <style> tags in the <head> section, in your (child) theme's header.php file. You can also load it with a hook in your (child) theme's functions.php file, or in the Custom Hooks add-on. To load the code only on pages with facets, use the facetwp_scripts hook. To load it on all pages, use wp_head or wp_footer. Or you can use a code snippets plugin. More info

/* Hide counts in all Time Since facets */ [data-type="time_since"] .facetwp-counter { display: none; } /* Hide counts in a specific Time Since facet */ .facetwp-facet-yourfacetname .facetwp-counter { display: none; }

Changelog

1.6.7

  • New added "Default label" UI setting
  • Fixed facet counter CSS class now matches other facets
  • Fixed linked to docs in the setting tooltip

1.6.5

  • New ability to use custom format ranges (see the doc page)
  • Fixed default to "OR" mode for all Time Since choices

1.6.4

  • Fixed User Selections facet was empty
  • Fixed use JS versioning to bust caching

1.6.3

  • Fixed filtering broken when labels are translated using `facetwp_i18n` hook

1.6.2

  • Improved changed textdomain to `facetwp-time-since`
  • Fixed choice labels can now be translated via the `facetwp_i18n` hook
  • Fixed undefined $token variable (props Rhys)

1.6

  • New revamped filtering logic to support "today", "tomorrow", and "yesterday"

1.5.1

  • Changed replaced `wp.hooks` to `FWP.hooks` due to conflict with WP 5.0

See also