Limit posts on a WP_Query and in WooCommerce product query

后端 未结 1 1256
离开以前
离开以前 2021-01-21 20:45

In Woocommerce, I need to limit post with a wp_query.

I know how to limit post in wp_query

For example if this page id is 20, I am running the quer

1条回答
  •  灰色年华
    2021-01-21 21:12

    The answer is… taratata!!!! :

    function wpcodex_filter_main_search_post_limits( $limit, $query ) {
        if ( get_the_ID()==20 ) {
            return 'LIMIT 25, 10'; 
        }
        return $limit;
    }
    add_filter( 'post_limits', 'wpcodex_filter_main_search_post_limits', 10, 2 );
    

    Because in 'LIMIT 25, 10';, here 25 is the offset and 10 the number of posts to display. So that way it will display 10 products beginning with the product 26…

    See this thread: Whats the difference between post_limits and pre_get_posts

    0 讨论(0)
提交回复
热议问题