Get Authors Role

As an alternative to “current_user_can” WordPress provides “user_can” which will take a User object or ID as a parameter. Combining your top code and the bottom code with the new function it would look like this: $author_user = $wp_query->get_queried_object(); // the queried object in ‘author.php’ should be an author user if (user_can($author_user, ‘buyer’)) { get_template_part( … Read more

get_comment_author_link not working properly

Simple solution drop this in your functions.php function your_get_comment_author_link () { global $comment; if ($comment->user_id == ‘0’) { if (!empty ($comment->comment_author_url)) { $url = $comment->comment_author_url; } else { $url=”#”; } } else { $url = get_author_posts_url($comment->user_id); } echo “<a href=\”” . $url . “\”>” .get_comment_author () . “</a>”; } If the user is registered this … Read more

Display more than 10 posts on author.php file

when you use the loop the number of post displayed is choosen fron the option set in Settings->Reading in you backend. It affects all the standard loops, not only the author page. To change only for author page you have to use pre_get_posts hook and set the wanted number of posts using posts_per_page argument: add_action(‘pre_get_posts’,’change_numberposts_for_author’); … Read more

Exclude specific user_id from args in get_comments

Looks like I had to figure this one out myself. replace $comment_meta_args and $replies with global $wpdb; $comment_meta_args=”SELECT * FROM `$wpdb->comments` WHERE `comment_approved` = 1 AND `comment_parent` = (“. intval($parent_comment_id) .”) AND `user_id` != 1 ORDER BY comment_date ASC LIMIT 3″; $replies=$wpdb->get_results($comment_meta_args);

Displaying Total Author View

The $current_user object retrieves the currently signed-in user. What you want is the ID of the author whose page you’re viewing. Try this: global $wp_query; $author_id = $wp_query->queried_object_id; $author_posts = get_posts( array(‘author’ => $author_id) ); $counter = 0; // needed to collect the total sum of views foreach ( $author_posts as $post ) { $views … Read more

Current author archive in navigation menu

Finally I figured it out and I am posting the solution for anyone who may be interested in such a workaround: function my_nav_menu_author_link( $menu ) { if( !is_user_logged_in() ){ return $menu; } else { $link = get_author_posts_url( get_current_user_id() ); $class = is_author() ? ‘ class=”current-menu-item”‘ : ”; $author_archive_link = ‘<li’ . $class . ‘>’ . … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)