Here is how I would solve your problem since $authordata
is not a variable that I recognize as a WordPress global.
function display_post_via_specific_author( $nicename ) {
// Grab the user by `user_nicename`
$author = get_user_by( 'slug', $nicename );
$posts = get_posts(
array(
'author' => $author->ID,
'posts_per_page' => 5
)
);
$output="<h5>Latest Posts by Sam</h5>";
$output .= '<ul>';
foreach ( $posts as $post ) {
$output .= '<li><a href="' . get_permalink( $post->ID ) . '">' . get_the_title( $post->ID ) . '</a></li>';
}
$output .= '</ul>';
return $output;
}
So it should be easy to query by author login calling the function like this:
echo display_post_via_specific_author( 'nick' );
Related Posts:
- How to run a function every 5 minutes?
- Upload Multiple Files With media_handle_upload
- Add custom template page programmatically
- What is the difference between get_page_link and get_permalink functions?
- How to override admin-bar style
- Woocommerce add to simple product attribute programmatically [closed]
- Breadcrumbs showing Parent and Child Pages
- mysql custom wp query
- TinyMCE custom stylesheets for different post types
- Order get_users() by last login date. Is it possible?
- Display random text from a file with the WP built-in AJAX API
- How do I properly register bootstrap JavaScript into WordPress functions.php?
- Function to Download External Images to My Site
- Manipulate Output of wp_list_something: select menu instead of li’s
- How to call a function on particular page like ‘contact-us’ from function.php of child theme
- Detect Safari desktop browser and include the detection in a shortcode
- Is It wrong to use oop approach on functions.php?
- How to preserve edits to Name or Slug of term when using wp_update_term on save?
- Woocommerce checkout field maxlength, make input number field only (postcode)
- how to fix Warning: Use of undefined constant _ – assumed ‘_’ (this will throw an Error in a future version of PHP)
- restore_current_blog required after switch_to_blog, if I use that in a function?
- ‘is’ functions and ‘get_query_var’ not working
- How Can I Expand the WordPress Customize window without any Plugin?
- Register and enqueue style.css custom theme
- How to hide a plugin metabox for non admins when a user adds a new post
- Getting Featured Image Caption to Only Show if Populated
- Where do I add html code to the menu div?
- How do I create page navigation linking to each H2 within the page? [closed]
- Add function to every post?
- Understanding and altering the structure of posted images
- What do the schemes login, login_post, admin, and relative mean?
- Allow Post Author to be 0 on Update
- How do I hide or remove ‘Category’ from wordpress breadcrumbs
- Trouble with adding a wp_enqueue_script on wordpress
- Display images that are not in the content
- Display ‘BuddyPress Follow’ follow button to non-logged in users [closed]
- Pagination in relation to archive.php
- wp-admin won’t load after setting wp-login custom url
- Incorrect redirect after commenting
- Get ID of first image attached to a post
- jQuery does not work
- Function naming convention
- Can’t call Javascript function – scope?
- Deprecated function get_user_by_email($email)
- Don’t display html if function returns nothing
- header_image() with CSS
- Shortcode parse error – wrong syntax
- Load custom css in functions.php causing library issue
- Why does get_template_directory_uri() not include “www”, only for enqueued stylesheets?
- Getting commenter meta
- In jquery use php variable to execute an enqueued jquery file
- Run a jquery script on on a certain template page
- How to stop media_sideload_image from running when deleting a post?
- I want to display latest post in marquee [closed]
- Add php code to wp_print_scripts?
- Remove ‘page-numbers’ class from prev and next tags
- Can’t add_action to ‘save_post’ and get it to fire
- How to load jQuery in TOP of wp_footer?
- How to fetch custom post type by variable date?
- How to make custom comment fields required
- two search forms on the same page
- Getting out side of wp root folder from function.php using absolute path
- How do I register a new settings page? [closed]
- Include Jquery libraries in wordpress theme?
- Change default upload images size for contributors
- Strange error from functions.php files (wp_register_script)
- Retrieve First Image Function
- User meta and public function security
- file.php not loaded?
- How to setup a popup registeration page in wordpress with function.php
- Display ACF category image on archive and single template files
- How to get taxonomy tree ids without running expensive loops
- Change WooCommerce Payment Options From Radio Buttons to Dropdown Menu
- Auto delete content in specific folder inside media library
- Using get_terms for custom taxonomy in functions.php
- Why does modifying the “read more” link remove the link class?
- How to update an image attachment’s alt text from a custom field when saving a post?
- Woocommerce product price change
- Allow user only create specific tags
- Child theme remove parent filter in functions
- Set URL Parameter Post Layout As Default
- How to display different blocks for mobile and desktops
- Help wiht adding fullcalendar.io to a WordPress page
- WP Enqueue Script Error
- Enqueue JS + CSS via a child theme functions.php file?
- How to add publish/draft button in Admin Post Lists
- Move product attributes after summary on single product page
- Woocommerce – change order status from on-hold to pending payment
- How to add number to wordpress count function?
- How do I integrate my Child Theme into a Custom Template?
- Sending Messages Back to the Template After Processing?
- Shortcode to eliminate and replace with
- Why are some custom javascript files working but some are not
- using enqueue_script in a shortcode isn’t working
- Functions file mods and CPU
- How to display milliseconds instead of seconds using timer_stop function? [closed]
- Filter to strip unnecessary attributes
- get_post_class() not working well
- Add functionality to block comment authors in the Comment edit pag
- WordPress enque the same script causes the setInterval not to work