Brain-WP / Cortex

Routing system for WordPress
MIT License
348 stars 20 forks source link

post__in not working #30

Closed bahreynipour closed 2 years ago

bahreynipour commented 2 years ago

Hi, I want to have a route with my desired woocommerce products based on "post__in". But seems it's not working and all of the products returns. Here is my code:

 add_action('cortex.routes', function(RouteCollectionInterface $routes) {

        $routes->addRoute(new QueryRoute(
        'store/{slug:[a-z-]+}',
        function(array $matches) {
            $founded_store = $matches['slug'];
            $post_in = KHS()->model()->get_products_ids_by_store_slug($founded_store);

            return [
                'post__in'          => $post_in,
                'post_type'         => 'product',
                'order_by'          => 'post__in',
                'order'             => 'ASC'
            ];
        }
   ));

});

i would appreciate if you would help

gmazzap commented 2 years ago

Cortex does nothing more than forward parameters to WordPress WP Query.

If some parameter is not working, that is on WP... but I doubt that is the case.

I think you should change order_by with orderby. See https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters