admin管理员组文章数量:1122832
I display a column from my pods table in the admin list, rendering it sortable and searchable. Each part of code is working fine. But when I search in that column and found the result, I cannot sort it any more: No result found and the list is empty Any idea how to solve this?
Here is my searching code:
function catalog_admin_search ( $join ) {
global $pagenow, $wpdb;
if ( is_admin() && 'edit.php' === $pagenow && 'catalog' === $_GET['post_type'] && ! empty( $_GET['s'] ) ) {
$join .= 'LEFT JOIN tableOne_catalog ON tableOne_posts.ID = tableOne_catalog.id';
}
return $join;
}
add_filter( 'posts_join', 'catalog_admin_search' );
function catalog_search_where( $where ) {
global $pagenow, $wpdb;
if ( is_admin() && 'edit.php' === $pagenow && 'catalog' === $_GET['post_type'] && ! empty( $_GET['s'] ) ) {
$where = preg_replace(
"/\(\s*tableOne_posts.post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(tableOne_posts.post_title LIKE $1) OR (tableOne_catalog.reference LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'catalog_search_where' );
As I use pods and a separate table, I filter via posts_clauses instead of pre_get_posts.
Here is my sorting code:
function catalog_sortable_column ( $clauses, $query ) {
if ( ! is_admin() || ! $query->is_main_query() ) {
return $clauses;
}
global $wpdb;
if ( $query->get( 'post_type' ) === 'catalog' && $query->get( 'orderby' ) === 'reference' ) {
$clauses['join'] .= " LEFT OUTER JOIN tableOne_catalog ON tableOne_posts.ID = tableOne_catalog.id";
$clauses['orderby'] = "tableOne_catalog.reference " . $query -> get('order');
}
return $clauses;
}
add_filter('posts_clauses', 'catalog_sortable_column', 10, 2);
Thanks for your help.
BTW, it sounds to be similar to this question
本文标签: Combining search and sort in the admin list using pods
版权声明:本文标题:Combining search and sort in the admin list using pods 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299947a1930640.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论