WooCommerce search products between price range using WP_Query

The solution: $query = array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘product’, ‘posts_per_page’ => 10, ‘meta_query’ => array( array( ‘key’ => ‘_price’, ‘value’ => array(50, 100), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘NUMERIC’ ), ), ); $wpquery = WP_Query($query); // return 10 products within the price range 50 – 100

Plugin init hook fires repeatedly

This happens because you are not excluding ajax requests. Check this example from the WordPress Codex for the admin_init hook which is also valid for the init hook and see how AJAX requests are exluded in the if using the DOING_AJAX constant: /** * Restrict access to the administration screens. * * Only administrators will … Read more

How to add single function for all WordPress hooks

There is a special action all that you can use. Be aware, this will be very slow, don’t do that in production. Here is an example: add_action( ‘all’, function() { static $hooks = []; $filter = current_filter(); if ( isset ( $hooks[ $filter ] ) ) return; $types = array_map( function ( $arg ) { … Read more

add_action in a custom plugin

It errors because class method is not a function. It’s not uniquely identified by its name alone. You need to provide instance of the object (or name of the class for static methods). In your context it would be: add_action( ‘init’, [ $this, ‘newsletterSuscriber’ ] );

Change plugin name on WordPress repo

You can change the name of your plugin, you just can’t change the url slug of your plugin. Meaning, if you initially added a plugin to the repo and it was called “Posts With Ad Thumbnails” your url would be: https://wordpress.org/plugins/posts-with-ad-thumbnails/ After uploading your plugin, if you decide to change the name just edit your … Read more

How to use my menu PHP code as sidebar?

wp_nav_menu is a standard WordPress function, so you would just copy/paste that PHP code into sidebar.php using whatever additional arguments you need. However, since the theme has a sidebar.php it probably has widget areas, so I would look in Appearance > Widgets in the dashboard and look for a sidebar widget area. In there, I … Read more