{"id":1497,"date":"2021-01-10T12:14:21","date_gmt":"2021-01-10T12:14:21","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/filter-order-grid-by-multiple-order-ids-magento-2\/"},"modified":"2025-07-21T17:11:55","modified_gmt":"2025-07-21T11:41:55","slug":"filter-order-grid-by-multiple-order-ids-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/filter-order-grid-by-multiple-order-ids-magento-2\/","title":{"rendered":"How to Filter Order Grid by Multiple Order IDs in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">An organized and flexible order grid is the sign of an advanced E-commerce store. There\u2019s no other alternative for managed order data when it comes to the order grid.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default,&nbsp;Magento 2&nbsp;order grid contains a number of columns for the ease of order processing. One can&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/add-custom-column-in-order-grid-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">add a custom column in Magento 2 Order grid<\/a>&nbsp;which is not available by default and&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/add-custom-mass-action-in-order-grid-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">add mass actions in the order grid in Magento 2<\/a>&nbsp;to get the things done quickly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, one can filter data by single order ID.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/12\/single-1-1024x405.png\" alt=\"Magento 2\u00a0order grid contains\" class=\"wp-image-12206\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In order to manage the order data in an efficient manner, it is required to expand features in the filtering. One of them is implementing&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/implement-multiselect-filter-for-order-status-in-magento-2-order-grid\/\">multiselect filter for order status in Magento 2<\/a>. Another essential addition is the ability to&nbsp;<strong>filter the order grid by multiple order IDs in Magento 2<\/strong>. You may require to filter the data by multiple order IDs to keep the track of some of the orders. Filtering them one by one becomes tedious. Thus, I\u2019ve come up with the programmatic solution to&nbsp;<em>filter order grid by multiple order IDs in Magento 2<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Steps to Filter Order Grid by Multiple Order IDs in Magento 2<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>di.xml<\/strong>&nbsp;at&nbsp;<strong><strong>app\\code\\Vendor\\Module\\etc<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\">\n    &lt;type name=\"Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\FilterApplierInterface\">\n        &lt;plugin name=\"sales_order_grid_filter_modifier\"\n                type=\"Vendor\\Module\\Plugin\\UiComponent\\DataProvider\\FilterApplier\"\n                sortOrder=\"1\"\/>\n    &lt;\/type>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>FilterApplier.php<\/strong>&nbsp;file at&nbsp;<strong><strong>app\\code\\Vendor\\Module\\Plugin\\UiComponent\\DataProvider<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Module\\Plugin\\UiComponent\\DataProvider;\n\nuse Magento\\Framework\\Api\\Filter;\nuse Magento\\Framework\\App\\Request\\Http;\nuse Magento\\Framework\\Data\\Collection;\nuse Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\FilterApplierInterface;\nuse Magento\\Sales\\Api\\Data\\OrderInterface;\n\n\nclass FilterApplier\n{\n    const SALES_ORDER_GRID_NAMESPACE = 'sales_order_grid';\n    protected $request;\n\n    public function __construct(\n        Http $request\n    )\n    {\n        $this->request = $request;\n    }\n\n    public function beforeApply(FilterApplierInterface $subject, Collection $collection, Filter $filter)\n    {\n        $namespace = $this->request->getParam('namespace');\n        if ($namespace == self::SALES_ORDER_GRID_NAMESPACE) {\n            if ($filter->getField() == OrderInterface::INCREMENT_ID) {\n                $modifiedFilterValue = str_replace('%', '', $filter->getValue());\n                $modifiedFilterValue = preg_replace('\/\\s+\/', '', $modifiedFilterValue);\n                if (strpos($modifiedFilterValue, \",\") !== false) {\n                    $filter->setValue($modifiedFilterValue);\n                    $filter->setConditionType('in');\n                } else {\n                    $filter->setValue('%' . $modifiedFilterValue . '%');\n                    $filter->setConditionType('like');\n                }\n\n            }\n        }\n        return [$collection, $filter];\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Done! Start adding comma separated order IDs in the Magento 2 order grid to filter them together and track as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/12\/double-1-e1608638188376-1024x476.png\" alt=\"2020\/12\/double-1.png\" class=\"wp-image-12208\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Quick enough, right?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento 2 community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An organized and flexible order grid is the sign of an advanced E-commerce store. There\u2019s no other alternative for managed order data when it comes&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1497","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1497"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1497\/revisions"}],"predecessor-version":[{"id":18815,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1497\/revisions\/18815"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}