I'm using the manage_posts_custom_column
filter to add some custom columns to the list post page.
I also have custom queries to retrieve data for those columns.
When this custom filter is combined with MB Admin Columns custom queries get altered by the plugin making them useless (the generated SQL is wrong).
I suspect this is a bug in the sort
and search
post functions in MB Admin Columns that are altering every query gets called on the list post page.
I think it can be easily fixed by checking if the query is the main one before altering it.
Here is a small patch:
--- a/inc/class-mb-admin-columns-post.php
+++ b/inc/class-mb-admin-columns-post.php
@@ -87,6 +87,10 @@ class MB_Admin_Columns_Post extends MB_Admin_Columns_Base {
* @param WP_Query $query The query.
*/
public function sort( $query ) {
+ if ( ! $query->is_main_query() ) {
+ return;
+ }
+
$orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING );
if ( ! $orderby || false === ( $field = $this->find_field( $orderby ) ) ) {
return;
@@ -120,6 +124,10 @@ class MB_Admin_Columns_Post extends MB_Admin_Columns_Base {
}
public function search( $query ) {
+ if ( ! $query->is_main_query() ) {
+ return;
+ }
+
$s = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
if ( ! $s ) {
return;