Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Show a text if the post has written by author user role in WordPress

This code will do it:

global $post;
$user = get_user_by( 'ID', $post->post_author );
if ( in_array( 'author', $user->roles ) ) {echo "Author";}

You don’t even need global $post; if you are if a query loop.

Related Posts:

  1. How to update custom fields using the wp_insert_post() function?
  2. Update value of a associative array with update_post_meta
  3. get value from get_post_meta then reuse it in another get_post_meta
  4. When working with a post, almost all wp_postmeta are deleted
  5. Post from front end form to post_meta
  6. How to display the date under the post title?
  7. How do I get a function to work in single.php
  8. How to show part of the_content?
  9. Unreadable pagination
  10. 200 Rewrite blog post links
  11. How to set a min number of words for a blog post
  12. Loop through categories and display posts title under each dropdown
  13. Get post id in a function when edit/add a post
  14. how do I get a specific post from a post with a subcategory in WP
  15. Sort custom meta column by other meta value
  16. Automatically create child pages and grandchild pages when saving a (parent) page
  17. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  18. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  19. wp_trim_words() does not work with my code Am I doing any mistake in my code?
  20. Creating user status mode in WordPress
  21. Second transition_post_status hook fired instead of the first
  22. Need help with Google drive API [closed]
  23. How to store post ID’s in cookie or session to display the same posts later
  24. Which hook/action will help me solve my problem?
  25. How can I add extra word in permalink when someone click download button?
  26. Post + form + action + results on the same page
  27. Open post-content in archive page in a Modal box with bootstrap
  28. remove post that has no content
  29. Archive post by meta value + 24hours
  30. Loading index.php contents which located outside blog folder for post single page
  31. get post content of particular post by url
  32. Post repeating with infinite scroll
  33. WordPress update_post_meta updating with empty meta_value field [closed]
  34. Custom posts in different columns style
  35. Get children post mime type using parent post_ID wp_post
  36. How to show only subcategories in parent category not parent category?
  37. 404 error when I acess the second page of post-type
  38. Which PHP page is the Default Posts Page
  39. Is it possible to retrieve all posts with a certain value for metadata?
  40. Get post id within comments loop
  41. retrieve post data and insert it in seperate static html page without WordPress
  42. WP Insert Post and then go to post
  43. Non-Closing PHP Query in WordPress Loop
  44. Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
  45. Returning data instead of echoing/printing
  46. Display related posts without a plugin
  47. Counting Search results, and displaying the offset per page
  48. Count posts on multisite with blog id
  49. Function works everywhere, how to keep it to execute when creating a new post
  50. Making (and edit existing) posts with ID included
  51. Copy taxonomy terms from one post to another programmatically
  52. Querying Database with wpdb
  53. Parsing Menu Items and Blog Posts
  54. Pagination on Custom Post
  55. $wpdb returns duplicate posts
  56. How to avoid duplicates when creating recent network posts
  57. How to show an entire post content and not also the excerpt?
  58. Get latest post from all categories except one
  59. What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
  60. Update post title from external file?
  61. Parse error: syntax error, unexpected end of file
  62. update_post_meta only updating on last loop of foreach
  63. how to get serialized post meta
  64. Automatically add images to a menu
  65. Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
  66. Load Posts on Click via Ajax into a DIV
  67. How to catch wordpress post ID when it’s published
  68. set post limit at load more ajax wordpress
  69. How to use two meta_compare in an array?
  70. WordPress query undefined offset in loop
  71. Find Site ID From WP_Post
  72. WP_Query: getting posts where custom field exists
  73. Array to string conversion on array_map
  74. Store metakey value as an array
  75. Increment paged on WP_Query
  76. Remove empty terms from array, sort alphabetically, update back to repeating field
  77. WordPress loop by meta key that is an array? and how loop multiple arrays
  78. Only show first image in foreach loop
  79. WordPress yoast seo plugin – parse snippet var in meta description
  80. How to use mysql LIKE with wpdb?
  81. How to store multiple custom meta box
  82. Reading settings in the home page precisely home.php
  83. Do I need to edit my theme in order to change the title of my blog page?
  84. Add new post in existing categories using wp_insert_post
  85. WordPress upload file size error even after raising php limits
  86. How do I add more options to the post-new.php page?
  87. get post id from wp_insert_post for get_template_part
  88. How to add post meta in while loop?
  89. create front-end users post list by specific category
  90. Incrementing PHP variable onclick to display posts by month
  91. Add category to post meta
  92. Modify main query before it run without pre_get_post
  93. Displaying list of posts in category page
  94. .html end of URl affected to SEO?
  95. Using rules in Posts
  96. How can I get “Previous” and “Next” to show in the navigation besides the links?
  97. Get the id of all images in a post
  98. Displaying content on posts page based on category
  99. Do not duplicate posts with multiple categories in multiple loops
  100. how to make an array of post id’s in is_single
Categories PHP Tags php, post-meta, posts
SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
WP meta_query args not working in function

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress