Redirect to page list when page published

I have the below code which works as expected if anyone else is looking for similar. add_action( ‘publish_page’, ‘redirect_user_page_list’, 10, 3 ); function redirect_user_page_list() { if( is_user_logged_in() ) { $user = wp_get_current_user(); $role = ( array ) $user->roles; if ( ‘role_slug’ == $role[0] ) { $url=”url to redirect to”; wp_redirect($url); exit; } } }

Set meta field to publish date + 2 weeks

Try this: add_action(‘publish_post’, ‘dp_expiry’); function dp_expiry( $data ) { /*adds 2 weeks onto the current date in unix epoch format*/ $dp_new_expiry_date = (strtotime( current_time( ‘mysql’ ) ) + 1209600); /*converts unix timstamp back to yyyy-mm-dd format like you required*/ $dp_new_expiry_date_conv = date(“Y-m-d”, $dp_new_expiry_date); update_post_meta( $data[‘post_id’], ‘postexpiry’, $dp_new_expiry_date_conv ); }

Post Meta Emtpy on Publish Using Transition

I got it working by looking at this post/answer: https://wordpress.stackexchange.com/a/134283/17126 Seems it can’t be done, and I changed the get_post_meta line to: $message .= ‘Email: ‘ . sanitize_text_field($_POST[‘_email’]) . ‘<br>’; Also, I could see the $_POST data coming in from post.php on submission over dev tools. And finally, I changed my hook to publish_cpt which … Read more

How to get the Tags on Publish post hook?

Found Solution : If there is no data in the request_body, the we can also fetch it from the postID which is already we have. Changed Code: added condition if data not available, then get it from post id public static function saveDataInNotificationTable($ID,$request_body) { $post_data = json_decode($request_body); $tags = $post_data->tags; if($post_data == “” || $post_data … Read more

Check if checkbox is marked on publish/update post

Working code: add_action( ‘acf/save_post’, ‘fritlaeg_artikel_3m’ ); function fritlaeg_artikel_3m( $post_id ) { if( get_post_meta( $post_id, ‘fritlaeg_artikel_i_3_maneder’, true ) ) { // Getting a UNIX Timestamp $timestamp = time(); // Using WordPress Time Constants // https://codex.wordpress.org/Easier_Expression_of_Time_Constants $timestamp_after_hour = $timestamp + 0.5 * MINUTE_IN_SECONDS; // Define remaining parameters $args = array( $post_id ); $hook = ‘fritlaegning_clear_meta_data’; // Get … Read more