Use Author Ids or Names to echo different output inside loop
<?php if (get_the_author_meta(‘ID’) == 7) : ?> Do something for user with ID 7. <?php else : ?> Do something for anybody else. <?php endif; ?> Try this, where 7 is the ID of the user.
<?php if (get_the_author_meta(‘ID’) == 7) : ?> Do something for user with ID 7. <?php else : ?> Do something for anybody else. <?php endif; ?> Try this, where 7 is the ID of the user.
$author = $wp_query->post->post_author; $author = get_user_by(‘id’, $author); author->user_nicename; That should get you the author slug which you can use in your conditional statement. get_the_author can only be used inside the loop.
Unless those authors register (or created a user card by admin) and log in in order to submit a post they are not users Also… (in case they are logged in) the form must record the current user and add that to the data being submitted… Additional information would require you to share with us … Read more
You can access the posts author (inside the loop) with the global $post; echo $post->post_author If your sidebar comes after your main content (in code), then you could populate a global array (not the best solution, but ok). // in the loop: Add each author to the global $post_authors array $post_authors[] = $GLOBALS[‘post’]->post_author; // in … Read more
this value comes from the template tag the_author(). You can also filter this. But it is important, that you check, that the filter only work on the feeds; see the follow example at the check for is_feed(). After this i change the autor name only, if the string has the value ‘name_xyz’; here is the … Read more
You could use this: <a href=”https://wordpress.stackexchange.com/questions/54419/<?php echo home_url() .”/author/’ . get_the_author_meta( ‘user_login’, wp_get_current_user()->ID ); ?>” >My Posts</a>
You can get the queried author in author.php with get_queried_object(): $author = get_queried_object(); echo $author->ID; $author_data = get_object_vars( $author->data ); echo $author_data[‘display_name’]; echo $author_data[‘user_url’]; echo $author_data[‘user_email’];
The key to this is covered on the get_posts codex page: Access all post data using the setup_postdata function: foreach ( $rand_posts as $post ) : setup_postdata($post); Regarding the_date, see the note about multiple instances on a page: SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only … Read more
the answer is provided here: Users with custom roles not showing in post author select box I tested and it works: to add a level_1 cap to your role. It’s PITA, considering how user levels have been deprecated so long ago, but there you go
Missing global ? global $post; No global variable available if you are using publish_post action hook! Ref : http://hungred.com/how-to/tutorial-post-id-publishpost-action-hook-wordpress/ Update 2 : or try this $author = get_userdata($post->post_author); So you can use $author where you will 😀