Display Author role in archive or author page

$authordata is not available before the first post is set up (before the first the_post();). But all the data you need are already there on an author archive: in get_queried_object(). It is a WP_User Object on the author archive. print ‘<pre>’ . htmlspecialchars( print_r( get_queried_object(), TRUE ) ) . ‘</pre>’; Result: WP_User Object ( [data] … Read more

Custom Author Fields + Existing Taxonomy – Integrating the Two Dynamically?

Figured it out, for anyone who needs help with this I’m sure you can use with categories/tags as well (can also use with radio inputs and checked=”checked”: <tr> <th><label for=”sorority”><?php _e(‘Sorority is…’) ?></label></th> <td><?php $sorority = get_the_author_meta( ‘sorority’, $user->ID ); ?> <select name=”sorority” id=”sorority”> <?php $terms = get_terms(‘sorority’); foreach ( $terms as $term ) { … Read more

Get author ID with attachment ID

Back in the day I wrote a function to check for that (you can put it in functions.php and call it from your page): public function check_if_user_is_author($user_id, $post_id) { global $wpdb; $res = $wpdb->get_results($wpdb->prepare(“SELECT * FROM ” . $wpdb->posts .” WHERE ID = %d AND post_author = %d LIMIT 1″, $post_id, $user_id)); if(isset($res) && count($res) … Read more

edit comments capability for authors

The role needs “edit_post” capability to edit comments (the reason beeing that comments are posts for wordpress) –> do your authors have “edit_post” capability? this enables the role to edit posts also, which might not be desired. WordPress capabilites are weird. There exists a meta capability ‘edit_comment’, but its not very intuitive. As far as … Read more

Total Word Count For Posts And Comments By One Author

Run a couple of queries and a code snippet to calculate the word count for the post content, comments content and tag names on each post. // This query will return the number of words in the post content $post_qry=”SELECT LENGTH(post_content) – LENGTH(REPLACE(post_content, ‘ ‘, ”))+1 from wp_posts where ID=”.$post_id; // This query will return … Read more

Show the author’s count of total amount of posts assign to a custom taxonomy term

/** * Get the author post count for a tax query. * * @link http://wordpress.stackexchange.com/q/159160/1685 * * @param array $tax_query * @return int */ function wpse_159160_get_author_posts_by_tax( $tax_query ) { global $wpdb; $where = get_posts_by_author_sql( ‘post’, true, get_post()->post_author ); $tax_query = new WP_Tax_Query( $tax_query ); $sql = $tax_query->get_sql( $wpdb->posts, ‘ID’ ); return ( int ) $wpdb->get_var( … Read more

Authors in menu, template list post by author

By default, you can view posts by authors with a URL of the form {home_url}/author/{author-slug}/ If you’ll be writing any PHP and need to output a link to an author’s posts, see the function get_author_posts_url. Edit: If you’ll be writing your own author post page template, the filename should be one of the following formats: … Read more

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