Block search SQL from happening

It’s possible to avoid SQL execution in WP_Query with the posts_pre_query filter. It’s e.g. used by plugins to outsource the default search to 3rd party search engines. Here’s an example how we can override the main search query on the front-end, with an empty posts array and avoid running the SQL search query: add_filter( ‘posts_pre_query’, … Read more

Find variables available at a given hook

In general the best solution would be to refer to the documentation for the hook – or the source for the action call within WordPress core’s codebase if the documentation proves insufficient. You can search the documentation for the relevant action or filter here. Many pages actually include the source of the filter/action call which … Read more

Is This A Correct Example Usage Of current_filter()?

Hi @Raj Sekharan: Looks good to me, but is wanting to know the current usage really your question or do you want to understand where current_filter() gets it’s information from? If the latter, here’s basically what happens in all the different hook processing functions, e.g. do_action(), apply_filters(), do_action_ref_array(), apply_filters_ref_array() (greatly simplified, of course): <?php function … Read more

Is it possible to add an action to the currently running action?

You have to use a later (higher) priority. So use current_filter() to get the current hook and priority, add 1 to that priority, and register the next action: add_action( ‘init’, ‘func_1’ ); function func_1() { global $wp_filter; $hook = current_filter(); add_action( $hook, ‘func_2’, key( $wp_filter[ $hook ] ) + 1 ); } function func_2() { … Read more

Using wp_ajax and wp_ajax_nopriv hooks

It depends on what exactly you want to do. If you want to show just a short message, use the same callback for both. But if you need completely different objects and load different additional files depending on the log-in status, use separate callbacks. Basic example, probably not a recommended implementation. 🙂 class Ajax_Controller { … Read more

How and why can a hook call itself without causing recursion?

This: apply_filters( ‘image_downsize’, false, $id, $size ) doesn’t call the image_downsize function, it applies any filters hooked to the image_downsize tag, which would be a different function. The only way that would cause recursion is if the filter you hook in turn called that function: add_filter( ‘image_downsize’, ‘wpd_downsize’, 20, 3 ); function wpd_downsize( $return, $id, … Read more

Issue adding text after short description on product pages Woocommerce [closed]

The Correct syntax for writing a add_filter // Define the woocommerce_short_description callback function filter_woocommerce_short_description( $post_excerpt ) { // make filter magic happen here… return $post_excerpt; }; // add the filter add_filter( ‘woocommerce_short_description’,filter_woocommerce_short_description’,10, 1 ); Your code didn’t work well because the reason is that filter are used to modify the output. Here is the function … Read more

Remove word “Category” from WooCommerce product page [closed]

This will definitely remove the word “category”. Add this code in functions.php.As you already know woocommerce_template_single_meta is the hook responsible for meta information of the single-product. File is present in /woocommerce/templates/single-product/meta.php. Either you can use the following code to edit the HTML of meta.php or you can copy the file meta.php to themes/your-theme/woocommerce/single-product/meta.php. Then edit … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)