問題描述
我需要在管理員中過濾我的帖子 Post-Formats?
我怎樣才能做到這一點 ?
現在,Wordpress 允許按類別和日期過濾。
最佳解決方案
嘗試這個外掛我煮熟了:
<?php
! defined( 'ABSPATH' ) AND exit;
/**
* Plugin Name: (#26032) WP_List_Table Post Format filter extension
* Plugin URI: http://wordpress.stackexchange.com/questions/26032/how-to-filter-by-post-format-in-admin
* Description: Filters the admin WP_List_Table by post format
* Author: Bainternet
* Author URI: http://en.bainternet.info
*/
function wpse26032_admin_posts_filter( &$query )
{
if (
is_admin()
AND 'edit.php' === $GLOBALS['pagenow']
AND isset( $_GET['p_format'] )
AND '-1' != $_GET['p_format']
)
{
$query->query_vars['tax_query'] = array( array(
'taxonomy' => 'post_format'
,'field' => 'ID'
,'terms' => array( $_GET['p_format'] )
) );
}
}
add_filter( 'parse_query', 'wpse26032_admin_posts_filter' );
function wpse26032_restrict_manage_posts_format()
{
wp_dropdown_categories( array(
'taxonomy' => 'post_format'
,'hide_empty' => 0
,'name' => 'p_format'
,'show_option_none' => 'Select Post Format'
) );
}
add_action( 'restrict_manage_posts', 'wpse26032_restrict_manage_posts_format' );
次佳解決方案
實際上,我實際上正在為您解決問題,只需重寫程式碼的幾個部分 (因為我基於另一個外掛,我寫的是相同的,但是對於層次結構型別的頁面模板) 。
這比 Bainternet 的外掛要大一些,所以一切手段堅持自己的解決方案,如果你對它很滿意 (不要覺得有義務切換是我所說的話),我打算釋出,為了任何可能感興趣的人。它適用於任何支援帖子格式的帖子型別。
編輯/更新:決定我可能會把程式碼放入一個正確的外掛,也做了相同的新增頁面模板過濾器到層級的帖子型別 (支援頁面模板) 。連結下面的任何人感興趣,
希望有幫助.. 🙂
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。