Post list based on the page author

As mentioned by @mridul-aggarwal WordPress supports author pages with the author.php template (Author_Template). If you are setting up a custom template you will need some method of letting the template discover which user is supposed to be displayed, this is usually done via a POST/GET request or in the URI http://example.com/path/to/user/username which you can then … Read more

Refine custom posts by author

Three steps need to be followed to accomplish it. 1. Add rewrite rules add_action(‘generate_rewrite_rules’, ‘author_cpt_add_rewrite_rules’); function author_cpt_add_rewrite_rules( $wp_rewrite ) { $new_rules = array( ‘author/(.+)/(.+)’ => ‘index.php?author=”.$wp_rewrite->preg_index(1) . “&post_type=” .$wp_rewrite->preg_index(2) ); //​ Add the new rewrite rule into the top of the global rules array $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } 2. Redirect to specific templates … Read more

Showing author page if user has no post

<?php $curauth = (isset($_GET[‘author_name’])) ? get_user_by(‘slug’, $author_name) : get_userdata(intval($author)); ?> <?php if ( have_posts() ) ?> <h2>Posts by <?php echo $curauth->nickname; ?>:</h2> <ul> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li> <a href=”https://wordpress.stackexchange.com/questions/106902/<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”> <?php the_title(); ?></a>, <?php the_time(‘d M Y’); ?> … Read more

Get author id from url

On an “author” page get_query_var(‘author’) will give you the ID. get_queried_object() will get you considerably more author information. $author = get_queried_object(); echo $author->ID; // var_dump($author); // to see all of the information available. For retrieving custom author data follow the Codex.

Display Authors in a grid loop

Definitely over thinking it <div class=”section group”> <?php printf(‘<h1>%s</h1>’, the_title()); foreach($users as $user) { ?> <div class=”author”> <div class=”col span_1_of_3″> <div class=”authorAvatar”> <?php echo get_avatar( $user->user_email, ‘128’ ); ?> </div> <div class=”authorInfo”> <h2 class=”authorName”><?php echo $user->display_name; ?></h2> </div> </div> </div> <?php } ?> </div>

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