Discuz! Board

 找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 2|回復: 0

编写您自己的自动建议高级搜索 WordPress 插件

[複製鏈接]

18

主題

18

帖子

58

積分

註冊會員

Rank: 2

積分
58
發表於 7 天前 | 顯示全部樓層 |閱讀模式
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
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|自動贊助|GameHost抗攻擊論壇

GMT+8, 2025-5-15 07:36 , Processed in 0.493804 second(s), 18 queries .

抗攻擊 by GameHost X3.4

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表
一粒米 | 中興米 | 論壇美工 | 設計 抗ddos | 天堂私服 | ddos | ddos | 防ddos | 防禦ddos | 防ddos主機 | 天堂美工 | 設計 防ddos主機 | 抗ddos主機 | 抗ddos | 抗ddos主機 | 抗攻擊論壇 | 天堂自動贊助 | 免費論壇 | 天堂私服 | 天堂123 | 台南清潔 | 天堂 | 天堂私服 | 免費論壇申請 | 抗ddos | 虛擬主機 | 實體主機 | vps | 網域註冊 | 抗攻擊遊戲主機 | ddos |