|
ajax php 1500@2x
Want to add advanced search functionality without depending on third-party plugins or themes? Build your own advanced WordPress Search Plugin with support for autosuggest, custom post types, taxonomies, custom fields, and caching from the ground up.
在本文中,我将向您展示如何构建一个面向对象的插件,以添加一个基于短代码的高级搜索表单,该表单可以使用自定义帖子类型 (CPT)、自定义分类法以及使用高级控制字段 (ACF) 创建的自定义元数据进行过滤。该搜索表单还将具有由 AJAX 支持的自动建议功能,并充分利用 WordPress 的瞬态机制来缓存结果。
While free plugins are a popular way to add greater functionality, they often come with their own set of problems. And there are so many factors to consider when getting that combination right. At times, developing your own plugin for areas that require a more fine-tuned approach may prove far more beneficial in the larger scheme of things. It will also allow you greater control over usability, performance and application security.
注意:本文面向中高级 WordPress 开发者。假设您具备 PHP、JavaScript、WordPress 循环、比利时商业传真列表 Transients 和 WordPress 插件 API 的应用知识。如果您想复习一下,建议您阅读以下内容:
Creating Custom Content in WordPress: Taxonomies and Fields
WordPress Development for Intermediate Users: Building Plugins
Advanced WordPress Development: Working With Transients
Advanced WordPress Development: Introduction to Object-Oriented Programming
为了本文,我准备了一个自定义 WordPress 插件,它可以通过短代码为任何 WordPress 页面添加一个启用自动建议的搜索表单。它还允许您将搜索结果微调到一个或多个自定义文章类型,并以弹性框网格布局显示它们。您可以从此处下载我的搜索插件,以便继续阅读本文。
Later in the article, I’ll extend the same plugin, and add complex search features such as filtering on multiple taxonomies and custom fields for a fictitious video library but the example can be easily extended to any scenario such as a product search or even faceted search.
CPTs and ACFs add tremendous power and functionality to WordPress, and are fairly common in any bespoke development project. My goal is to help you integrate several such advanced WordPress features to play together in a real-world application. So let’s get started!
Note: For the rest of the article and throughout the code, the term Post Type refers to the default Posts and Pages post types as well as any registered Custom Post Types.
Flow of Control of the Custom Search Plugin
|
|