How to properly delete custom post type posts programmatically

I believe I found the problem. Since the wp_delete_post was before the redirect, WordPress tried to reload an inexistent page (and comments, since they are deleted automaticaly with the command) and that generated the error. The new code is as such and it’s not generating errors: if( has_post_thumbnail( $post_id ) ) { $imagem_principal_id = get_post_thumbnail_id( … Read more

Filter DELETE REST API calls

pre_delete_post hook filters whether a post deletion should take place. So callback function must return a boolean value: true – whether to go forward with deletion, false – if not. pre_trash_post hook filters whether a post trashing should take place. So callback function must return a boolean value: true – whether to go forward with … Read more

Remove post if exist by title

The s parameter of WP Query search posts within the title and content columns of the posts table. You can use that to shorten your code. Here is a sample bit to help you get started. You can hook it in wp_footer to run only once (very bad idea to keep it there, but good … Read more

How to update the delete user confirmation form?

On the Users (wp-admin/users.php) page, WordPress uses wp_dropdown_users() to generate the users drop-down menu you’re referring to, so I’d suggest using the wp_dropdown_users_args hook to filter the users query, e.g. to show only 1 result (or 10, but surely not 55k!) and then use JavaScript to add/load the other results. So in this answer, I’m … Read more