WordPress custom post type edit post url
-
On my website I have created a custom post type for listings. Clients can add listings on the front-end from the my-account page, and when they do, the admin is being notified by an email, containing the edit url of the newly added listing post. So when the admin clicks on the url in the email, he is being redirected directly to the edit screen of the listing post in the backend of WordPress.
This is how the e-mail looks like: https://prnt.sc/11wyj3r
This all works fine when the admin is not logged in yet, before clicking on the link in the email. But when the admin is already logged in on the site, he is being redirected to the default blog post overview page in the backend.
Why is that and more importantly, how can we fix it?
My code:
function wgoe_send_admin_notification( $post_id, $post, $update ) { // If the post type is not a project, don't send the email if (get_post_type($post_id) != 'project') return; // If this is a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) return; // If post is being published, don't send the email if (get_post_status( $post_id ) == 'publish' ) return; $post_url = get_edit_post_link( $post_id ); $subject = 'A listing has been added or updated'; $message = "Howdy Admin! \n\n\n"; $message .= "A user has added or updated a listing on your website. Please check the listing for publication:\n\n"; $message .= $post->post_title . ": " . $post_url . "\n\n\n"; $message .= "Dive Business For Sale"; // Send email to admin. $adminemail = get_option( 'admin_email' ); // $adminemail = '[email protected]'; wp_mail( $adminemail, $subject, $message ); remove_action( 'wp_insert_post', 'wgoe_send_admin_notification', 10 ); } add_action( 'wp_insert_post', 'wgoe_send_admin_notification', 10, 3 );
The page I need help with: [log in to see the link]
- The topic ‘WordPress custom post type edit post url’ is closed to new replies.