=== Ajax Filter Search: Filter Posts by Category, Date & Keyword === Contributors: longislandfreelancewebdesigner Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=34C7NUYWTVYFA Tags: ajax filter, filter posts, live search, category filter, custom post type Requires at least: 6.0 Tested up to: 7.1 Requires PHP: 7.4 Stable tag: 2.3.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Let visitors filter and search posts or custom post types by category, month, year and keyword, with no page reload. Shortcode and block included. == Description == Ajax Filter Search is a small but powerful plugin that displays your posts or custom post type in a list or grid with category tabs, search, month and year filters and pagination, all using ajax so there's no page reload. A visitor can filter your posts by search keyword, month, year and category to get the exact content they're looking for. It's a great tool for anyone looking to show a reel of press releases, blog posts, upcoming events, whatever you can think of. Choose from four designs: an **Editorial Grid** of image cards with category badges, excerpts and dates, a compact **Resource Library** of searchable rows with thumbnails, the clean Modern design, or the original Classic look. The two newest designs take their colors from your theme, so they work on dark themes too. = Features = * **Gutenberg block and shortcode** - Add the "Ajax Filter Search" block, or use the `[ajax_filter_search]` shortcode anywhere. * **Multiple feeds per page** - Every feed has its own post type, categories, layout and filters. * **Shareable links** - The first feed on a page keeps its filters and page number in the address bar, so a filtered view can be bookmarked or shared, and the back button works. It also works with JavaScript turned off. * **Fast, light front end** - Plain JavaScript (no jQuery), a small stylesheet, and assets that load only on pages that contain a feed. No external fonts or icon libraries. * **Editorial Grid and Resource Library designs** - Image cards with category badges, excerpts and dates, or compact rows with optional thumbnails. Choose what each one shows (featured image, image shape, columns, excerpt length, date, time, category badge) under Settings > Cards, or per feed. * **Modern and Classic designs** - A clean, card-based Modern design for new installs and the original Classic look for sites that already use the plugin. Choose one site wide or per feed. * **Works with dark themes** - The Editorial Grid and Resource Library take their borders, surfaces and text from your theme's colors, with no extra setting. * **Block patterns** - Add a ready-made Editorial Grid or Resource Library from the block inserter in one click, then change anything in the block sidebar. * **Pick terms by name** - In the block, choose the categories to limit a feed to from a searchable list instead of typing slugs. * **Sort and filter chips (optional)** - Let visitors sort by newest, oldest, A to Z, recently updated or most commented, and show the active filters as removable chips with a Clear all link. Both are off until you turn them on. * **RSS feed for any view** - Every filter state has its own RSS 2.0 feed at `/wp-json/afs/v1/feed`, built from the same query as the results and listing published posts only. * **Accessible** - Labeled form fields, keyboard friendly tabs and buttons, live-region updates and a current-page indicator. * **Easy to theme** - Set your accent color in Settings, or override any `--afs-*` CSS variable. Developers can override the item template and use filters. * **Settings panel** - Choose the default post type, taxonomy, posts per page, layout and more under Settings > Ajax Filter Search. = Example shortcodes = [ajax_filter_search] [ajax_filter_search terms="news,press-releases" posts_per_page="12" layout="grid"] [ajax_filter_search post_type="event" post_tax="event_type" orderby="title" order="ASC" show_views="false"] [ajax_filter_search design="editorial" columns="3" image_ratio="16:10" excerpt_length="25"] [ajax_filter_search design="library" show_sort="true" show_chips="true"] = Shortcode attributes = All attributes are optional. Anything you leave out uses the setting from Settings > Ajax Filter Search. * `post_type` - post type slug. * `post_tax` - taxonomy slug used for the category tabs (or `none`). * `terms` - comma separated term slugs to limit the feed to. (`filter_by` and `filter_type` are accepted as older names for the same thing.) * `posts_per_page` - 1 to 100. * `layout` - `list` or `grid`, the layout the feed starts in. * `orderby` - `date`, `title` or `modified`. `order` - `DESC` or `ASC`. * `search` - a keyword to start with. `filter_years` / `filter_months` - start on a year (for example 2025) or month (1 to 12). * `show_tabs`, `show_views`, `show_search`, `show_months`, `show_years` - `true` or `false`. * `design` - `modern`, `classic`, `editorial` or `library`. Overrides the Appearance setting for this feed. * Card options for `editorial` and `library` (Classic and Modern ignore them; anything you leave out uses Settings > Cards): `show_image`, `show_excerpt`, `show_date`, `show_time`, `show_category` - `true` or `false`. `image_ratio` - `16:10`, `3:2`, `4:3`, `1:1` or `16:9` (Editorial Grid only; Resource Library thumbnails are square). `columns` - 1 to 4, the most columns the Editorial Grid uses (it shows fewer on narrow screens). `excerpt_length` - 10 to 80 words. * `show_sort`, `show_chips` - `true` or `false`. The sort control and the active filter chips are off unless you turn them on here, in the block, or under Settings. = Please Rate Ajax Filter Search! = Your ratings make a big difference! If you like and use Ajax Filter Search, please consider taking the time to [rate the plugin](https://wordpress.org/support/plugin/ajax-filter-search/reviews/). Your ratings and reviews will help this plugin grow and provide the motivation needed to keep pushing it forward. == Frequently Asked Questions == = What are the steps to getting Ajax Filter Search to display on my website? = 1. Add the "Ajax Filter Search" block, or copy the shortcode `[ajax_filter_search]`, into your page. 2. Optionally adjust the defaults under Settings > Ajax Filter Search. 3. View the page and watch Ajax Filter Search fetch your posts. = Is it possible to only display posts from 1 or 2 categories? = Yes. Add the `terms` attribute with the term *slugs* you want, separated by commas, for example `[ajax_filter_search terms="news,events"]`. Make sure the slugs belong to the taxonomy selected for that post type. (If you used `filter_by` with an older version, it still works.) = Can visitors sort the results or see which filters are active? = Yes, both are optional. Add `show_sort="true"` for a sort control and `show_chips="true"` for removable filter chips with a Clear all link (they also offer a way out when nothing matches). You can also use the matching block controls, or turn them on for every feed under Settings > Ajax Filter Search. They are off by default, so existing feeds look exactly as before. = How do I show featured images, or change what each card shows? = Use the Editorial Grid or Resource Library design (Settings > Ajax Filter Search > Appearance, `design="editorial"` or `design="library"` on a feed, or the block's Design setting). Then set what each card shows under Settings > Cards, or for one feed with `show_image`, `image_ratio`, `columns`, `show_excerpt`, `excerpt_length`, `show_date`, `show_time` and `show_category` (the block has the same controls). A post with no featured image gets a tinted tile in the Editorial Grid and no thumbnail in the Resource Library. The image and excerpt of a password-protected post are never shown. = Will it work on a dark theme? = Yes for the Editorial Grid and Resource Library: their borders, surfaces and muted text are derived from your theme's text color, so a dark theme gives a dark feed. Modern and Classic use their own light colors. = Can I add a feed in one click? = Yes. In the block inserter, open Patterns and look for the "Ajax Filter Search" category: an Editorial Grid and a Resource Library, each already set up. Developers can turn the patterns off with `add_filter( 'afs_register_patterns', '__return_false' );`. = Is there an RSS feed for a filtered view? = Yes. `/wp-json/afs/v1/feed` accepts the same parameters as the results endpoint (for example `afs_term=news&afs_year=2025`) and returns RSS 2.0 with published posts only. Developers can build the address with `afs_feed_url()` or remove the feed with `add_filter( 'afs_enable_feed', '__return_false' );`. = Will search engines index every filtered view? = No. A page that shows a feed and is opened with a filter, search or page number in the address is marked noindex, follow, so only the main page is indexed. You can turn this off under Settings > Ajax Filter Search or with the `afs_noindex_filtered_states` filter. = Is the ajax functionality secure? = The filters call a read-only REST endpoint (`/wp-json/afs/v1/results`) that only ever returns published content of public post types. All incoming values are validated and sanitized on the server, and the endpoint cannot change anything on your site, so no nonce is needed. = I'm upgrading from 1.x. What changes? = Version 2.0.0 is a major update. Please back up your site and try it on a staging copy first. The feed has new markup and a small new stylesheet, so custom CSS written for the old Bootstrap-based markup needs updating, and the Font Awesome icon font is no longer loaded. Theme template overrides keep working. A compatibility layer keeps the 1.x functions, constants, the first feed's element IDs, the old script handles and the old ajax action working for now; it is deprecated and can be switched off with `add_filter( 'afs_enable_legacy_compat', '__return_false' );`. The `filter_by` attribute now limits a feed to category slugs, as the 1.x readme described; use `search` for a starting keyword. A short migration guide is in the plugin's GitHub repository (docs/MIGRATION-1.x-to-2.0.md). = Can I change how each result looks? = Yes. Copy `afs-template/default.php` (Classic and Modern), `editorial.php` or `library.php` from the plugin folder into `your-theme/afs-template/` (a child theme is checked first) and edit it. Templates written for version 1.x keep working. You can also use the `afs_query_args` and `afs_template_file` filters. = Does it load anything from third-party servers? = No. Version 1.x loaded Font Awesome from a CDN on every page. Version 2.0.0 loads nothing external. = Can I keep the old look? = Yes. The Classic design is the look of earlier versions, and sites that already use the plugin keep it. New installs start with the Modern design. Change it under Settings > Ajax Filter Search > Appearance, or for one feed with `design="classic"` or `design="modern"` (the block has a Design setting too). = How do I change the colors? = Pick the accent color under Settings > Ajax Filter Search. For more control, set CSS variables in your theme, for example `.afs { --afs-accent: #0a7; --afs-radius: 0; }`. = What happens to my data if I uninstall? = The plugin's single settings option is removed when you delete the plugin. Your posts are never touched. == Installation == = Using The WordPress Dashboard = 1. Navigate to 'Add New' in the plugins dashboard 2. Search for 'Ajax Filter Search' 3. Click 'Install Now' 4. Activate the plugin on the Plugin dashboard = Uploading in WordPress Dashboard = 1. Navigate to 'Add New' in the plugins dashboard 2. Navigate to the 'Upload' area 3. Select `ajax-filter-search.zip` from your computer 4. Click 'Install Now' 5. Activate the plugin in the Plugin dashboard = Using FTP = 1. Download `ajax-filter-search.zip` 2. Extract the `ajax-filter-search` directory to your computer 3. Upload the `ajax-filter-search` directory to the `/wp-content/plugins/` directory 4. Activate the plugin in the Plugin dashboard == Screenshots == 1. The Editorial Grid design: photo cards with category badges, excerpts, search, sorting and filters. 2. The Resource Library design: compact, searchable rows with optional thumbnails. 3. The Editorial Grid on a phone: search comes first, and the category pills wrap instead of clipping. 4. The new designs take their colors from your theme, so they work on dark themes. 5. Active filter chips and a sort order, kept in the address bar so the view can be shared. 6. The settings screen: choose a design and what each card shows. 7. The block in the editor, with the Cards controls and the searchable term picker. 8. Two independent feeds on one page, each with its own design and its own filters. 9. An empty result says what was searched and offers one clear way to reset the filters. 10. The Classic design, the look of earlier versions. == Changelog == = 2.3.1 = * Fixed: A password-protected post no longer shows its featured image or excerpt in the Editorial Grid, the Resource Library, the results route or the RSS feed, whether or not the visitor has entered the password. * Fixed: Cached results now also refresh when a featured image file or its details are replaced or edited. * Fixed: A feed with `show_chips="false"` on a site where chips are on keeps its chips off after an Ajax update. * Fixed: In the block's term picker, terms that share a name (for example in different parent categories) can each be chosen; they are told apart by their slug. * Improved: On phones the layout switch sits beside the result count, and the category tabs use the full width. It works in right-to-left languages too. * Improved: The settings screen shows one shortcode with a "More examples" list, puts the design choice first and has shorter Cards text. * Improved: New plugin banner and icon, and retaken screenshots. * Classic and Modern feeds, shortcodes, saved settings, bookmarked links and theme template overrides are unchanged. = 2.3.0 = * New: Editorial Grid design (image cards with category badges, excerpts and dates) and Resource Library design (compact searchable rows with optional thumbnails). Choose them under Settings > Appearance, with `design="editorial"` or `design="library"`, or in the block. Existing sites keep their current design. * New: Cards settings for what each result shows: featured image, image shape, columns, excerpt and its length, date, time and category badge. Set them site wide under Settings > Cards or for one feed with shortcode attributes or the block. * New: The Editorial Grid and Resource Library take their colors from your theme, so they work on dark themes. * New: Block patterns for both designs, and a searchable term picker in the block instead of typing slugs. * New: A dismissible "What's new" card on the settings screen for sites that already use the plugin. It makes no outside requests and never appears on a fresh install. * Improved: The Editorial Grid and Resource Library have one compact toolbar (the layout switch sits beside the category tabs as two icon buttons), a search placeholder, a Reset button only when it is needed, a clearer empty result, aligned Resource Library rows, a refined missing-image tile and tighter spacing on phones. * New: Developers can register a design with its own item template (`afs_register_design`) and turn the patterns off (`afs_register_patterns`). * Improved: The Cards settings hide options that do not apply (image shape when images are off, excerpt length when excerpts are off, the time when the date is off) and keep their saved values. In the block, "Use plugin setting" shows the current default. * Improved: Cached results now refresh when a featured image or attachment changes. * Improved: Retaken screenshots. * Classic and Modern feeds, shortcodes, saved settings, bookmarked links and theme template overrides are unchanged. = 2.2.2 = * Fixed: The short description was 2 characters over the WordPress.org limit and was cut off in search results. Shortened it. No change to behavior, settings or output. = 2.2.1 = * Improved: Clearer plugin name and description in search results and the Plugins list. No change to behavior, settings or output. = 2.2.0 = * New: Modern design with card-based results, pill tabs, a cleaner filter bar and a segmented layout switch. New installs get it by default. Sites that already use the plugin keep the Classic look until they choose Modern (Settings > Appearance, `design="modern"` on a feed, or the block's Design setting). * New: Redesigned settings screen with section navigation, a design picker, copyable example shortcodes and a sticky save bar. * Improved: Text on the accent color is now white or dark depending on the color you choose, so buttons stay readable with any accent, in both designs. * Fix: Submitting a search no longer sends a second, delayed request that could undo a click on a tab or page link made right afterwards. = 2.1.0 = * New: Optional sort control (newest, oldest, A to Z, recently updated, most commented). Turn it on with `show_sort="true"`, the block control or Settings. * New: Optional active filter chips with Clear all, and a "Clear all filters" link when nothing matches (`show_chips="true"`, the block control or Settings). * New: RSS 2.0 feed for any filter state at `/wp-json/afs/v1/feed`. It uses the same query as the results and lists published posts only. * New: The results endpoint returns a `meta` block and, for logged-out visitors, sends cache validators so a repeat request is answered with an empty 304. * New: Filtered views of a feed page are marked noindex, follow so only the main page is indexed (setting, on by default). * New: A dismissible notice for administrators when the theme has template overrides or styles written for 1.x, with a link to the migration guide. * New: Extension points for add-ons: registries, the `afs_register` action, `afs_rest_response`, `afs_cache_version`, `afs_feed_url()` and JavaScript hooks and events (`afs:loaded`, `afs:results`, `afs:error`). * Improved: The Update button is hidden when JavaScript is active. It stays for visitors without JavaScript. * Improved: If an update request fails, the first feed on a page falls back to a normal page load and any other feed shows a Try again button. * Improved: The category tab list is cached. * Fix: In the block editor, clicking the preview no longer sends the editor canvas to a raw REST address; the preview is inert and a click selects the block. * Security: Only published content can be listed, even if a site's `afs_query_args` filter tries to widen the post status. = 2.0.0 = * New: Gutenberg block with editor controls and live preview. * New: Multiple feeds on one page, each with its own settings. * New: Shareable, bookmarkable filter state in the address bar for the first feed on a page; works without JavaScript; back button supported. * New: Shortcode attributes `terms`, `layout`, `orderby`, `order`, `search`, `show_tabs`, `show_views`, `show_search`, `show_months`, `show_years`. `filter_by` now does what the old documentation said (limit to category slugs). * New: Accent color setting and `--afs-*` CSS variables. * New: Settings for the default layout; `afs_query_args` and `afs_template_file` filters. * Security: Replaced the old admin-ajax handler with a validated read-only REST endpoint, escaped all output, and validate all settings on save. Includes every fix from 1.0.4. * Improved: Front end rewritten in plain JavaScript (jQuery no longer required) with a small, scoped stylesheet. Assets load only on pages that use the plugin. * Improved: Accessibility - labeled fields, ARIA states, keyboard friendly controls, announced updates. * Improved: Fully translatable; dates and month names follow the site language and settings. * Improved: Works with PHP 7.4 to 8.4 and WordPress 6.0 to 7.1; removed all PHP warnings from earlier versions (for example when two feeds shared a page). * Improved: Child themes are checked for template overrides; the settings page and its scripts only load on the plugin's own screen. * Added: A deprecated compatibility layer for 1.x code: the 1.x functions, classes and constants, the old ajax action (now served by the same validated code), the first feed's 1.x element IDs, the old script and style handles, and the `ajaxurl` / `scriptpath` globals on feed pages. Switch it off with the `afs_enable_legacy_compat` filter. * Removed: The Font Awesome CDN, the bundled Bootstrap-derived CSS, SCSS sources and development junk from the plugin package. * Added: `uninstall.php` removes the plugin's setting on deletion. = 1.0.4 = * Security: Hardened the ajax request handler. All submitted values are now validated. * Security: Draft, scheduled and pending posts are no longer included in ajax results. * Security: The settings-screen taxonomy lookup is now limited to administrators. * Fix: Filtering no longer causes a fatal error on PHP 8. = 1.0.3 = * Function / Structure Improvements * Bug fixes to address Page loop error. * Added a template capability to the loop to allow for customization in the future. * Added "filter_by" attribute to the shortcode to allow for selected categories in the loop * Began ground work for color selection options in settings page = 1.0.2 = * Update to test Version # = 1.0.1 = * CSS Edits, A Few Bug Fixes, Added Screenshots, Robots text edits, Compiled SCSS files = 1.0.0 = * Ajax Filter Search == Upgrade Notice == = 2.3.1 = Fixes password-protected posts appearing with an image or excerpt in the new designs, and a few smaller problems. Existing feeds look exactly as before. Recommended. = 2.3.0 = Adds two optional designs (Editorial Grid and Resource Library) with featured images, excerpts, card settings, block patterns and dark-theme support. Existing feeds look exactly as before until you choose a new design. Recommended. = 2.2.2 = Shortens the plugin description so it is no longer cut off in search results. No functional changes. = 2.2.1 = New plugin title, description and tags to make the plugin easier to find. No functional changes. = 2.2.0 = Adds an optional Modern design (the default for new installs) and a redesigned settings screen. Sites that already use the plugin keep the Classic look unless they switch. Also fixes a delayed duplicate request after submitting a search. Recommended. = 2.1.0 = Adds optional sort, filter chips and an RSS feed (all off by default), cache validators for the results endpoint and noindex for filtered views. Existing feeds render as before. A site filter can no longer widen the post status beyond published. Recommended. = 2.0.0 = Major update. Back up your site and test on a staging copy first. The new markup and styles replace the old Bootstrap-based ones, so custom CSS, JavaScript and code that calls the legacy AJAX action may need adjusting. 1.x template overrides keep working. = 1.0.4 = Security update. Recommended for all users.