Force new posts to the top of query loop

Here’s a suggestion using posts_orderby filter and CASE, UNIX_TIMESTAMP and DATEDIFF (that outputs number of days) from MySQL for conditional SQL ordering: add_filter( ‘posts_orderby’, function( $orderby, $q ) use (&$wpdb) { if( ! $q->is_main_query() ) { return $orderby; } return $wpdb->prepare( ‘CASE WHEN DATEDIFF( %i.post_date, NOW() ) <= 14 THEN -UNIX_TIMESTAMP( %i.post_date ) ELSE %i.post_title … Read more

“Invalid parameter(s): attributes” issue in context of “blocks.registerBlockType” filter

In what way is the Tag Cloud block different? That block is a dynamic block, which uses a live rendering using ServerSideRender, and the documentation stated that “If you pass attributes to ServerSideRender, the block must also be registered and have its attributes defined in PHP“, therefore, custom attributes for the block must be defined … Read more

Can I send a body using wp_remote_get()?

I think I’ve figured out the solution. The short answer is GET requests don’t usually have a body, but wp_remote_get() will take what one assigns to the body argument and make it into URL parameters. That’s why it expects an array (because each element of the array becomes a parameter added to the URL). One … Read more

Filter “wp_mail” – How to distinguish between a WordPress system email and a plugin email?

I agree with @birgire that #53829-core would be the ideal way to do this. If you need a hack that works in the meantime, though, then you can examine the filenames in the call stack. add_filter( ‘wp_mail’, ‘modify_system_emails’ ); function modify_system_emails( array $attributes ) : array { $wp_mail_caller = get_wp_mail_caller(); if ( is_core_file( $wp_mail_caller[‘file’] ) … Read more

add custom filter to plugins page?

you can do that with the help of 2 filters : add_filter(“plugins_list”, function ($plugins) { $filter_code = “with_b”; if ( isset($_GET[“plugin_status”]) && ($filter_code === $_GET[“plugin_status”]) ) { $GLOBALS[“status”] = $filter_code; // setting the filter to display in current page } // preparation of the plugins in the special category $plugins[$filter_code] = array_filter($plugins[“all”], function ($plugin) { … Read more