>本文说明了如何使用WordPress过滤器自定义邮政管理屏幕。 我们将介绍WordPress的内置过滤器,并向您展示如何创建自定义过滤器以增强功能。
关键概念restrict_manage_posts
pre_get_posts
>可以通过将代码添加到主题的functions.php
pre_get_posts
创建自定义过滤器
> WordPress提供内置过滤器时,您通常需要自定义的过滤器才能获得更好的用户体验。 两个钩子是关键:
:将新的过滤器控件添加到管理员屏幕的顶部。
- :在查询运行之前修改查询,过滤显示的帖子。
-
restrict_manage_posts
>示例:作者和邮政格式过滤 - >让我们为邮政作者和格式创建过滤器。 想象一个网站,帖子手动分配了格式和作者。默认的管理屏幕可能是压倒性的。 我们将添加下拉菜单以易于过滤。
pre_get_posts
> 添加下拉菜单(
>将以下代码添加到您的主题的
>文件(或插件):
restrict_manage_posts
>按邮政格式过滤:
functions.php
>
function add_author_filter() { global $post_type; if ($post_type == 'post') { $user_args = array( 'show_option_all' => 'All Authors', 'orderby' => 'display_name', 'order' => 'ASC', 'name' => 'author_filter', 'who' => 'authors', 'include_selected' => true ); if (isset($_GET['author_filter'])) { $user_args['selected'] = (int) sanitize_text_field($_GET['author_filter']); } wp_dropdown_users($user_args); } } add_action('restrict_manage_posts', 'add_author_filter');
>过滤帖子列表(
function add_post_format_filter() { global $post_type; if ($post_type == 'post') { $post_formats_args = array( 'show_option_all' => 'All Formats', 'orderby' => 'NAME', 'order' => 'ASC', 'name' => 'post_format_filter', 'taxonomy' => 'post_format' ); if (isset($_GET['post_format_filter'])) { $post_formats_args['selected'] = sanitize_text_field($_GET['post_format_filter']); } wp_dropdown_categories($post_formats_args); } } add_action('restrict_manage_posts', 'add_post_format_filter');)
现在,让我们使下拉列表功能:
>作者过滤:
pre_get_posts
>通过邮政格式过滤:
这些函数将查询修改为仅包含匹配所选作者或邮政格式的帖子。
function filter_posts_by_author($query) { global $post_type, $pagenow; if ($pagenow == 'edit.php' && $post_type == 'post' && isset($_GET['author_filter'])) { $author_id = sanitize_text_field($_GET['author_filter']); if ($author_id != 0) { $query->set('author', $author_id); } } } add_action('pre_get_posts', 'filter_posts_by_author');
结论
这通过自定义过滤器增强了您的WordPress管理员。 您可以通过其他帖子属性(请参阅WordPress查询类文档)进行过滤。 请记住要始终对用户输入进行消毒以防止安全漏洞。
>以上是定制的WordPress管理过滤器的详细内容。更多信息请关注PHP中文网其他相关文章!

Yes,youcanuseWordPresstobuildamembershipsite.Here'show:1)UsepluginslikeMemberPress,PaidMemberSubscriptions,orWooCommerceforusermanagement,contentaccesscontrol,andpaymenthandling.2)Ensurecontentprotectionwithupdatedpluginsandadditionalsecuritymeasures

你不需要编程知识就能使用WordPress,但掌握编程可以提升体验。1)使用CSS和HTML可以调整主题样式。2)PHP知识能编辑主题文件,添加功能。3)自定义插件和元标签可优化SEO。4)注意备份和使用子主题以防更新问题。

TosecureaWordPresssite,followthesesteps:1)RegularlyupdateWordPresscore,themes,andpluginstopatchvulnerabilities.2)Usestrong,uniquepasswordsandenabletwo-factorauthentication.3)OptformanagedWordPresshostingorsecuresharedhostingwithawebapplicationfirewal

WordPressExcelSoverotherWeberteBuilderSduetoItsflexible,可伸缩性,andopen-sourcenature.1)它'saversatilecmswithExtEnsextEnsiveCustomizedOptionsVIATHEMESANDPLUGINS.2)它的alllearbutoffersbutoffersbutoffersbutoffersbutofferspopelyContrololonCemastered.3)

2025年网站开发的七个必备WordPress插件 在2025年建立顶级WordPress网站需要速度,响应能力和可扩展性。 实现这种有效的实现通常取决于战略插件的选择。 这篇文章Highlig

WordPresscanbeusedforvariouspurposesbeyondblogging.1)E-commerce:WithWooCommerce,itcanbecomeafullonlinestore.2)Membershipsites:PluginslikeMemberPressenableexclusivecontentareas.3)Portfoliosites:ThemeslikeAstraallowstunninglayouts.Ensuretomanageplugins

是的,wordpressisisexcellentforcortingaportfoliowebsite.1)itoffersnumeroversnumeroverportfolio-spificthemeslike'astra'astra'astra'astra'astra'astra'astra'astra'astra'elementor'Enelementor'enableIntiviveSiveSign,Thoughtemanycanslowthesite.3)

WordPressisadvantageousovercodingawebsitefromscratchdueto:1)easeofuseandfasterdevelopment,2)flexibilityandscalability,3)strongcommunitysupport,4)built-inSEOandmarketingtools,5)cost-effectiveness,and6)regularsecurityupdates.Thesefeaturesallowforquicke


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境