I want to limit all products. For example, if I have 135 products stored in the database, then I want to display 50 (latest) products.

enter image description here

Is there a hook or can I modify any file?

Note:I don't want to limit the products per page using posts_per_page

I wrote this function. Yes, it works, but it doesn't change the fields of the whole table. For example, ALL remains the same enter image description here

function limit_total_admin_products($where, $query) {
global $wpdb;

if (is_admin() && $query->is_main_query() && $query->get('post_type') === 'product') {
    $max_products = 50;
    $where = " AND {$wpdb->posts}.ID IN (
        SELECT ID FROM (
            SELECT ID
            FROM {$wpdb->posts}
            WHERE post_type = 'product'
            ORDER BY ID DESC
            LIMIT {$max_products}
        ) as latest_products

return $where;}
add_filter('posts_where', 'limit_total_admin_products', 10, 2);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.