Maybe this would work?
function ps_pre_get_products_query( $query ) {
$per_page = filter_input(INPUT_GET, 'perpage', FILTER_SANITIZE_NUMBER_INT);
if ( ! is_admin() && is_woocommerce() && is_page() ) {
$query->set( 'posts_per_page', $per_page );
}
}
I tested your code and the if statement didn’t seem to work with is_page()
(but that could also be because my local WP sandbox is a mess). To my knowing posts_per_page
expects int
and var_dump
showed that $per_page
was a string.
EDIT My local WP sandbox is a mess, so that’s why is_page
wasn’t working. I tested the code again on another install.
EDIT 2 Let’s see how many times I can get this wrong. I updated the code to something that works (at least on another local WP sandbox).
Related Posts:
- WooCommerce create new product and add to cart on form submit
- Over write plugin templates
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- Change wordpress current_time function to different timezone
- How to enable specific plugin only based around shop manager role?
- Replacing a plugin function with a custom renamed function doesn’t work
- Redirect to another page using contact form 7? [closed]
- Replacing global wp_query
- wc_get_template new template does not showing up
- WordPress Stock Update Programatically
- Woocommerce singe product custom gallery output works just on the first slide
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- How to get custom minimum price in Woocommerce
- How to make WooCommerce payment method field optional?
- Create category for each user
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- ACF Fields are not showing up on Homepage
- Adding discount functionality to the cart
- How to assign a specific service to a specific provider based on location
- Make modification of add_to_cart button specific to single page
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- Securing langugae folder
- Configuring default woo commerce login with modal popup
- Move related products after product summary? [closed]
- is_plugin_active() not defined on active plugin, in the thumbnails.php file
- WooCommerce custom query and paging: Not Found error
- Woocommerce – Product Description heading [closed]
- Woocommerce disable checkout on specific day
- Adding a script & php to functions.php
- Override the plugin class and function
- Product customizing quiz – quiz adding products to the cart
- Show WooCommerce products based on query parameters on redirect
- Hide prices and checkout functionality in woocommerce
- Plugin update error message
- How to handel multiple checkbox field in the admin settings page with Settings API
- wp_insert_user – how to send verification email before logging in
- Set a User as Author of all ‘New Posts’ posted
- What is the function to get plugin base url in multisite?
- Code in theme functions.php faster than with a plugin?
- Override the core function locate_template
- Trying to count the total number of paragraphs inside a blog article
- How to get post URL in the_content filter?
- Manually add order item with fixed product_id in WooCommerce
- Pass info from functions.php to plugin
- add_query_arg not working
- Why required field not working in Country dropdown in WooCommerce –
- How to check current user before all actions and filters?
- WooCommerce specifc variations for specific user role [closed]
- Display Custom Field Value on Admin Page Column
- List the authors that have written posts in a category
- How to get plugin name from plugin file location
- How to get a list of bundled products using wp_query in woocommerce
- How to get the particular product quantity in orders in Woocommerce [closed]
- add_query_arg not work in admin
- How to remove a class function from a plugin by using remove_action()?
- Api external with wordpress
- Sell access to form [closed]
- Hook for altering the content of all wp mails
- I want to filter my products with attributes [closed]
- How to get rid of Ellipsis on Woocommerce [Essential] Theme [closed]
- Sharing functions between plugins
- Permalinks and pagination are not working in WordPress with WP e-Commerce plugin
- Automatic recurring payment using YITH subscription and Dokan Stripe
- apply_filters(woocommerce_get_item_data, …) Causing errors when adding to cart
- Change Dashboard URL from wp-admin to wp-admin/index.php
- How To Use do_shortcode with WooCommerce One Page Checkout
- Hide fields in woocommerce settings
- implement custom roles in custom plugin
- How to get current cart values using WC_Shortcodes?
- How to copy the all WordPress media items to another custom plugin folder?
- show wc_add notices on particular page in woo commerce custom plugin development
- best way to handle subscriptions with a licence?
- how can export data in excel file custom plugin
- woocommerce with external ftp site
- WordPress eMails not working
- Add WooCommerce vendor slug to auto-generated SKU
- WP_CRON issue with UTC and local time
- How to wrap image tag into div for post only?
- Update User Meta Via Ajax
- how to make settings page for woocommerce plugin?
- redirect to a custom page
- Problem with conditional woocommerce custom checkout field
- Unexpected plugin_dir_path Output
- How woo-commerce store Product Data value in DB?
- how to create table during plugin installation in side a class
- Which WordPress version to use for improved plugin compatibility? [closed]
- Metabox Data not saving
- Can’t get custom user meta to show in header
- Including a PHP file via a function that is part of a plugin?
- Pass strings to plugin function [closed]
- WP Members additional fields on user profile [closed]
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Trying to disable all notifications except for one on woocommerce checkout page with css [closed]
- Translate text for empty product
- How to Add Extra Text In WordPress Title Before Post Publish
- How can I make a quotation engine like this website in WooCommerce?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- WordPress Convert queries to slashes using function.php
- ShipStation WooCommerce Integration error
- Add Text in Single Product Page On a Specific Category