Hot answers tagged

9

At the moment, it is not possible. When 'pre_get_posts' runs, is too late to stop WP_Query to perform a query. WordPress itself, when you try to query a taxonomy that does not exists, adds AND (0 = 1) to the WHERE clause of the SQL query, to ensure it returns no results very quickly... There's a trac ticket with a patch that will probably lands in core ...


5

It is not a bug. As @LuisSanz pointed out, post_type_link isn't used for the built-in post post type. It is used for custom post types only. Skim through get_permalink() function, you will find out that WordPress doesn't use post_type_link filter but uses post_link filter. It means that you're using wrong filter. Then, change post_type_link to post_link ...


4

Looking at the sources (core files, wp-includes/option.php) you can always find your target hook tags: add_action("added_option", "wpse230212_callback_add", 10, 2); add_action("updated_option", "wpse230212_callback_update", 10, 3); function wpse230212_callback_add( $option_name, $option_value ) { } function wpse230212_callback_update( $option_name, $...


4

Your analogy here is partially correct, but incomplete: I understand that when do_action is called wp looks for all registered listeners and invokes them according set priority. You need to consider what happens when you call add_action. WordPress never searches for the add_action statements, it has those in a list. When you call add_action, it ...


3

do_action( 'deactivate_' . $plugin, $network_deactivating ); Fires as a specific plugin is being deactivated. do_action( 'deactivated_plugin', $plugin, $network_deactivating ); Fires after a plugin is deactivated. The above hooks don't fire when silent mode is activated (eg: during an update). Refer: deactivated_plugin


2

It will be made possible in 4.6 (assuming no changes till release) with the new posts_pre_query filter https://core.trac.wordpress.org/ticket/36687


2

The dynamic filter "term_{$field}" is probably what you're looking for, where the field is "name." One approach is to have an array of names and their pseudonyms, then do a check-and-return on them so they'll display the replacement. add_filter( 'term_name', function( $value ) { $terms = [ 'old' => 'new', ]; // basic example check, ...


2

This is PHP question more than a WordPress question. As @Mark commented: returning from the action do not return by magic from the calling function That is true. Placing return in function mean exit the function and placing return in a PHP file mean exit the file. Do not get confused with PHP construct exit() :P (You might find a better answer on SO ...


1

Yep it's possible depending on what you want to cache. I've done a similar thing to cache the main loop on our homepage. Essentially you can use the posts_request and posts_results to hijack the query and hit the cache instead then also use found_posts to correct the pagination. Really rough example pulled from our code (untested) but you should help you ...


1

If you hook into the hooks provided in update_post_meta() function and still use this function in your callback, that would result in a loop which would probably end with the timeout.. As the per the comments: add_action("wp_insert_post", function( $post_ID ) { if ( ! $post_data = get_post( $post_ID ) ) return; // try to make this run only once ...



Only top voted, non community-wiki answers of a minimum length are eligible