Hot answers tagged

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.
user avatar
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 );
user avatar
  • 1,194
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 ...
user avatar
  • 426
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 ...
user avatar
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('...
user avatar
  • 2,230
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( $...
user avatar
  • 52.5k
10 votes

Echo author ID in author.php

Try this simply code if (is_author()){ $author = get_queried_object(); $author_id = $author->ID; }
user avatar
  • 221
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 ...
user avatar
  • 136
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(...
user avatar
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(...
user avatar
  • 3,144
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 ...
user avatar
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(...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 76.2k
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 ...
user avatar
  • 276
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, ...
user avatar
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['...
user avatar
  • 8,589
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', ...
user avatar
  • 64.1k
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 ...
user avatar
  • 589
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; $...
user avatar
  • 63.6k
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 ...
user avatar
  • 2,893
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. */ ...
user avatar
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 ...
user avatar
  • 6,383
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 ...
user avatar
  • 139
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....
user avatar
  • 64.1k
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 ...
user avatar
  • 181
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 ...
user avatar
  • 141
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:...
user avatar
  • 2,085
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 ...
user avatar
  • 180
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</...
user avatar
  • 5,322

Only top scored, non community-wiki answers of a minimum length are eligible