It can be done like this without having to rely on the $post global.
if ( is_admin() ) {
if( isset( $_GET['post'] ) && isset( $_GET['action'] ) && $_GET['action'] === 'edit' ) {
$post_id = $_GET['post'];
$current_post = get_post($post_id);
$author_id = $current_post->post_author;
}
}
The query string variable post
is always the post_id
you are editing and additionally you need to check if the action
query variable is set and it equals to edit
.
Additionally you can explore the get_current_screen() function to setup more advanced conditionals for better security.
Related Posts:
- Get_the_author doesn’t return author name
- Unreadable pagination
- Posts missing on author page
- Query all posts of a custom taxonomy term
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Getting a specific post values to another div or modal
- Trying to add attribute to my posts’ featured image
- Displaying the last post on static homepage
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- How to create a form and display its content as table in admin panel?
- Best practice for migration friendly images in posts/pages?
- Storing Array from returned database query and using the array in a new query
- How to show part of the_content?
- Getting the author name on author archive page
- Namespace spl_autoload problem in WordPress admin
- 200 Rewrite blog post links
- remove wp floating submenu in wp dashboard
- How to set a min number of words for a blog post
- My custom wp-admin php files stopped working
- Loop through categories and display posts title under each dropdown
- Get post id in a function when edit/add a post
- how do I get a specific post from a post with a subcategory in WP
- Automatically create child pages and grandchild pages when saving a (parent) page
- Call to undefined function wp() in wp-blog-header.php
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Cannot access wp-admin (wordpress dashboard)
- Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
- Second transition_post_status hook fired instead of the first
- Remove metabox from WordPress menu editor page?
- How to store post ID’s in cookie or session to display the same posts later
- Which hook/action will help me solve my problem?
- How to make my custom widget appear within WordPress widgets? Plugin development
- How can I add extra word in permalink when someone click download button?
- Post + form + action + results on the same page
- Open post-content in archive page in a Modal box with bootstrap
- PHP version problem?
- edit_comment_link is not showing for comment author
- remove post that has no content
- Programmatically create page when saving custom post type post
- WordPress admin is incredibly slow [closed]
- inserting a post from an extern php file but post content doesn’t show on wp site
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Post repeating with infinite scroll
- Custom posts in different columns style
- Get children post mime type using parent post_ID wp_post
- How to show only subcategories in parent category not parent category?
- 404 error when I acess the second page of post-type
- How to change menu labels
- Remove author link wherever author’s name is display
- Which PHP page is the Default Posts Page
- WordPress admin-ajax.php
- retrieve post data and insert it in seperate static html page without WordPress
- How can I open up my administrative panel to everyone?
- WP Insert Post and then go to post
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Returning data instead of echoing/printing
- How do I modify the custom footer text and get theme version number to show in wordpress admin?
- Display related posts without a plugin
- Counting Search results, and displaying the offset per page
- Count posts on multisite with blog id
- Function works everywhere, how to keep it to execute when creating a new post
- Making (and edit existing) posts with ID included
- WordPress ajax-action failing because of newline in response
- Copy taxonomy terms from one post to another programmatically
- get_total () returns 0 – woocommerce [closed]
- Parsing Menu Items and Blog Posts
- Pagination on Custom Post
- $wpdb returns duplicate posts
- How to avoid duplicates when creating recent network posts
- How to show an entire post content and not also the excerpt?
- Get latest post from all categories except one
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Update post title from external file?
- Parse error: syntax error, unexpected end of file
- Link blogname and blogdescription to the Options Framework
- retain querystring values when savincustom options in admin
- Usage of call back function of add_meta_box()
- Automatically add images to a menu
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Load Posts on Click via Ajax into a DIV
- How to catch wordpress post ID when it’s published
- set post limit at load more ajax wordpress
- AJAX wp_insert_user WORKS but responds with “The site is not enabled”
- WordPress query undefined offset in loop
- WordPress wp-admin redirect and exception
- Find Site ID From WP_Post
- WP_Query: getting posts where custom field exists
- Noindex Posts From Certain Authors In WordPress
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Only show first image in foreach loop
- How to use mysql LIKE with wpdb?
- Reading settings in the home page precisely home.php
- Override Admin menu icon
- Do I need to edit my theme in order to change the title of my blog page?
- Add new post in existing categories using wp_insert_post
- Using admin-post.php for admin form but it directs me to admin-post.php white screen