39
votes
get post author id outside loop
The easiest way would be using get_post_field():
$post_author_id = get_post_field( 'post_author', $post_id );
For more details on this issue: have a look at this StackOverflow answer.
21
votes
Accepted
Programatically change post author
It shouldn't be any problem. Try this:
$arg = array(
'ID' => $post_id,
'post_author' => $user_id,
);
wp_update_post( $arg );
16
votes
Select subscriber as author of post in admin panel?
As of WordPress 4.4.0 you can now use the wp_dropdown_users_args filter. The code is much simpler now:
add_filter( 'wp_dropdown_users_args', 'add_subscribers_to_dropdown', 10, 2 );
function ...
16
votes
Accepted
How to remove the author pages?
The above answer is good, but if redirecting to home page, it should specify a 301 status and exit after.
add_action('template_redirect', 'my_custom_disable_author_page');
function ...
13
votes
Accepted
Publish author posts only with editor approval?
Add the following code to your functions.php:
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
if ( current_user_can('...
11
votes
Accepted
Making Wordpress author follow button, need missing ingredient
I would advise you not to use the user meta. Although your problem is caused by:
update_post_meta( $author_id, "_user_followed", $followed_USERS ); // Add user ID to author meta
update_post_meta( $...
10
votes
Echo author ID in author.php
Try this simply code
if (is_author()){
$author = get_queried_object();
$author_id = $author->ID;
}
9
votes
Get List of all the Authors
Use function get_users(). It returns an array of all authors. With foreach it is possible to loop over the array and display its content. There are a lot of attributes going with the user object. Here ...
9
votes
Get only the author profile picture image url inside a loop
Putting the following inside loop should fulfill your needs:
<?php
$get_author_id = get_the_author_meta('ID');
$get_author_gravatar = get_avatar_url($get_author_id, array('size' => 450));
if(...
8
votes
Accepted
Hook that get's triggered when the author of a post is changed
There is no special hook to author change.
But you can achieve it by using post_updated hook.
Example:
add_action('post_updated', 'prefix_on_update_author', 10, 3);
function prefix_on_update_author(...
8
votes
How to remove the author pages?
You can also add the redirect to the author template directly. In your WordPress theme, edit the author.php file to redirect users to your homepage. If your theme doesn't have a template for author ...
7
votes
Accepted
How to display all images "Uploaded By" an author
You can do it via WP_Query loop:
$args = array(
'author' => $author_id, // Replace with author id
'post_status' => 'any',
'post_type' => 'attachment'
);
$query = new WP_Query(...
7
votes
How to force listing contributors in authors dropdown menu
You can just use wp_dropdown_users_args filter instead of creating metabox
add_filter('wp_dropdown_users_args', 'display_administrators_and_subscribers_in_author_dropdown', 10, 2);
function ...
6
votes
Accepted
Displaying custom post types in author.php
I'll guess that you don't set $authorid anywhere, so it's being ignored and returning all posts regardless of author. If you enable debugging, you'll get a warning telling you that $authorid is ...
6
votes
Accepted
Give Author users the right to embed
The capability you are after is called unfiltered_html. Some options:
Modify author capabilities in your theme functions.php. This is saved in the DB, so you can access a page, make sure it works ...
5
votes
add capability to author role to be able to delete attachments
Here is how to allow edition and deletion of attachments for owned ones only to a custom role.
Add the capabilities 'manage_other_users_attachments' and 'manage_own_attachments' to the admin role, ...
5
votes
Accepted
Display Authors Comments on Profile Page
What you need to use here is the WP_Comment_Query() function.
So on the author.php page, you can easily get the author info and ID as followed:
// get author info
$curauth = (isset($_GET['...
5
votes
Accepted
the_author_posts_link css class
You can use the the_author_posts_link filter to add the custom blog-link class:
/**
* Add the 'blog-link' class to the output of the_author_posts_link()
*/
add_filter( 'the_author_posts_link', ...
5
votes
Accepted
How can I add an Author filter to the Media Library?
In your question you showed the image which is grid-view and that codex belongs to list-view. So I am confused here for which section you are talking about.
Grid View : not possible unless you change ...
5
votes
Accepted
Show one post per author and limit query to 8 posts
I believe that you can achieve this effect by grouping the query by author ID, which will require a filter(mostly cribbed from the Codex):
function my_posts_groupby($groupby) {
global $wpdb;
$...
5
votes
Accepted
Missing Author Information
To display the author's avatar within The Loop use get_avatar() like that:
<?php print get_avatar(get_the_author_meta('ID'), '30', '', '', ['class' => 'foo-bar']); ?>
To display the ...
4
votes
Force display name as full name
A better solution is to update the display name every time the user is updated. I'm resorting this old thread because I cannot find this solution anywhere.
/* First name as default display name. */
...
4
votes
Accepted
How to add editor's name to entry meta byline?
Here's a small screenshot of what this code produces:
Demo Editor is a new user i added with Editor status and then logged in as Demo Editor and modified a post to test this solution works.
You can ...
4
votes
Get_the_author doesn't return author name
Though echoing worked for the OP, the issue could be related to setting up the post manually, as was in my case. Here is the code:
$post = get_post();
setup_postdata($post); // setting up the post ...
4
votes
Accepted
Check If comment author is registered
I wonder if you mean this kind of check:
if( $comment->user_id > 0 ) {
// Registered comment author
}
in your comment's template callback.
This is determined in the the wp-comments-post....
4
votes
Get the comment author ID by the comment ID
you should use it: <?php get_comment( $id, $output ); ?>
Return
comment_ID
(integer) The comment ID
comment_post_ID
(integer) The post ID of the associated post
comment_author
(string) The ...
4
votes
Check if author or current user has posts published
diving into this I found that count_user_posts() is a better solution. it's shorter, and also cheaper in resources than get_posts();
so here it is:
$user_id = get_current_user_id(); //the logged in ...
4
votes
Change destination author link
To only edit the link associated with authors, in the functions.php of your theme:
add_filter( 'author_link', 'new_author_link', 10, 1 );
function new_author_link( $link ) {
$link = 'http:...
4
votes
Accepted
Remove author link wherever author's name is display
You have actually two problems to solve here:
The first one is to remove the HTML link, which you are trying to achieve right now. As you read in the comments, it depends on your theme. You could ...
4
votes
Generate an Email address from that of the Post Author
Try using author_meta.
<?php
$author_email = get_the_author_meta('user_email');
?>
<a href="mailto:<?php echo $author_email;?>?subject=<?php the_title(); ?>">Apply</...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
author × 865posts × 119
custom-post-types × 65
comments × 61
users × 56
author-template × 56
functions × 50
user-roles × 50
php × 49
plugins × 41
wp-query × 40
categories × 36
loop × 34
profiles × 31
pages × 28
user-meta × 28
list-authors × 28
permalinks × 27
customization × 22
url-rewriting × 22
archives × 22
post-meta × 21
admin × 20
slug × 19
custom-field × 18