Custom Fields
Re-Envisioned
Support MB Admin Columns Bug: MB Admin Columns alters custom queries

  • Creator
    Topic
  • #13878
    Resolved vubai
    Participant

    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;
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #13881
    Anh Tran
    Keymaster

    Hi vubai, thanks a lot for your feedback and the fix. I’ll add that to the plugin and release a new version.

    Update: Version 1.4.1 has been released with the fix!

    #13887
    vubai
    Participant

    Thank you for this quick release!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.