How can I specify the post status of an untrashed post?

I think for your purpose wp_untrash_post_status filter will be enough. Will work with single and multiple posts restore. Filters the status that a post gets assigned when it is restored from the trash (untrashed). add_filter( ‘wp_untrash_post_status’, ‘change_untrash_post_status’); function change_untrash_post_status($status){ return ‘pending’; } P.S. apply_filtershook is used to call callback functions created by us, like a … Read more

retrieve post details in loop

First, change those = to === as mentioned by @sally-cj in the comment. On top of that, you’re saving the status as a variable called $stat and are then checking it as $status. So you might want to change $stat = get_post_status($job->ID); into $status = get_post_status($job->ID);. Or better: the $job is already populated with a … Read more

custom post type, hide or disable the status line in publish meta box

WordPress doesn’t provide any filter/hook to override the existing HTML in post submit metabox. So, either you remove the entire metabox and add your own (which will be overkill in your case) or just hide it using CSS or remove that element using JS. function wpse406970_remove_publishing_actions() { global $typenow; if ( $typenow == ‘YOUR_CPT’ ) … Read more

Auto-change Post Status on First Page Load

If you want the default post status to be in-progress when contributors click on “New Post”, then you can try the following: /** * Set default post status as ‘in-progress’ for contributors * * @link https://wordpress.stackexchange.com/a/143128/26350 * * @param array $data * @return array $data */ function wpse_143100_wp_insert_post_data( $data ) { $current_user = wp_get_current_user(); if( … Read more

Programmatically change post visibility on save_post action return a 500

There is some information about this problem in the Action Reference for save post: If you are calling a function such as wp_update_post that includes the save_post hook, your hooked function will create an infinite loop. To avoid this, unhook your function before calling the function you need, then re-hook it afterward. So something like … Read more

Ajax function on #publish only saves as draft – how to make it publish?

Perhaps this solution will work: var flag_ok = false; $(‘#publish’).on(‘click’, function (e) { if ( ! flag_ok ) { e.preventDefault(); var url = shiftajax.ajaxurl; var shift = $(‘#post_ID’).val(); var data = { ‘action’: ‘wpaesm_check_for_schedule_conflicts_before_publish’, ‘shift’: shift, }; $.post(url, data, function (response) { if( response.action == ‘go’ ) { // there aren’t any scheduling conflicts, so … Read more