How to untrash a post only if it was not a draft?

Just as @cybmeta mentioned, the info is stored in the post meta table. When we trash a post then the post meta key _wp_trash_meta_status is added with the value of the previous post status (publish, pending, draft, … ). Within the wp_trash_post() function, we have: add_post_meta($post_id,’_wp_trash_meta_status’, $post[‘post_status’]); add_post_meta($post_id,’_wp_trash_meta_time’, time()); We might therefore try: // Get … Read more

wp_transition_post_status does not change the status of the post

This function contains do_action() calls for post status transition action hooks. The order of the words in the function name might be confusing – it does not change the status of posts, it only calls actions that can be hooked into by plugin developers. https://codex.wordpress.org/Function_Reference/wp_transition_post_status What you want is wp_update_post, you’re also using WP_Query incorrectly: … Read more

Which is the better way to get the status of a post?

None of them. A, C and D all indicate that you’re inside a loop, and want the status for the current post. But if that’s the case then the first line on all of them is redundant. This is all you’d need if you want the status of the ‘current post’: $current_post_status = get_post_status(); get_post_status() … Read more

How to Modify this $wpdb query to accept an array of post statuses

Use the IN operator for arrays. When using $wpdb->prepare() you don’t have to use quotes around the string placeholder %s. The string placeholder will be quoted automatically. That’s also the reason why you have to take precautions when using $wpdb->prepare() with the IN operator if the array values are strings. This first example doesn’t use … Read more

Can’t get drafts with WP_Query using post_status parameter

Try passing it as an array. For example $args = array( ‘p’ => 1234, ‘post_type’ => ‘any’, ‘post_status’ => array(‘draft’) ); Or for all types $args = array( ‘p’ => 1234, ‘post_type’ => ‘any’, ‘post_status’ => array(‘publish’, ‘pending’, ‘draft’, ‘auto-draft’, ‘future’, ‘private’, ‘inherit’, ‘trash’) );

‘transition_post_status’ only fires when pressing “Add New”

This will do something when you publish a post in the backend. function my_publish( $post_id ) { if ( ( $_POST[‘post_status’] === ‘publish’ ) && ( $_POST[‘original_post_status’] != ‘publish’ ) ) { error_log(‘WordPress would be better if it did not use Google Fonts. Looking forward to the system fonts.’); } } add_action( ‘publish_yourCustomPostType’, ‘my_publish’, 10, … Read more

add filter to “quick edit menu” in wordpress admin

You do not want to reference the global $post, but the post that is given to you as one of the argument. You simply need to remove global $post; Remember also to sanitize input and prefix function names. function wpse50651_filter_transition_post_status( $new_status, $old_status, $post ) { global $wpdb; $wpdb->query( $wpdb->prepare( “UPDATE my_table SET post_status=%s WHERE post_id=%d”, … Read more