在何处可以在“媒体列表查询”中另外插入条件。总之,我想对Posteta表的元值应用一些过滤器。我尝试使用以下sql获取值。但我没有得到任何零钱。
我修改了文件wp admin/includes/class wp media list表中的函数“prepare\\u items()”。php
公共功能prepare\\u items(){
global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
/**
*
* paul lee
*
*/
$q_args = $_REQUEST;
$meta_query = array(
array(
\'key\' => \'meta_value\',
\'value\' => \'%cloudinary%\',
\'compare\' => \'NOT LIKE\'
)
);
$q_args[\'meta_query\'] = $meta_query;
list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q_args );
/*-----------------------------------------------*/
$this->is_trash = isset( $_REQUEST[\'attachment-filter\'] ) && \'trash\' === $_REQUEST[\'attachment-filter\'];
$mode = empty( $_REQUEST[\'mode\'] ) ? \'list\' : $_REQUEST[\'mode\'];
$this->set_pagination_args( array(
\'total_items\' => $wp_query->found_posts,
\'total_pages\' => $wp_query->max_num_pages,
\'per_page\' => $wp_query->query_vars[\'posts_per_page\'],
) );
}
我不确定meta\\u查询是否也会应用于POSTETA表。我需要你的专业帮助。谢谢
SO网友:Ahmed Fouad
正如评论中所说,编辑WP核心文件不是一个好主意。通过向插件或主题函数添加以下代码,可以轻松修改显示媒体帖子的查询。php
add_filter( \'pre_get_posts\', \'_wp_media_pre_get_posts\' );
function _wp_media_pre_get_posts( $wp_query ) {
global $pagenow;
if( ! in_array( $pagenow, array( \'upload.php\', \'admin-ajax.php\' ) ) )
return;
$wp_query->set( \'meta_query\', array(
array(
\'key\' => \'meta_value\',
\'value\' => \'%cloudinary%\',
\'compare\' => \'NOT LIKE\'
)
) );
}