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

Get author total post votes from post meta

Assuming that you have a loop within your author.php file, grab the required metadata for every post within it, add it into a variable and display that after the loop has finished:

$author_vote_count = 0; //declare vote count variable before the loop

<?php while ( have_posts() ) : the_post(); ?>

    // the stuff going on in your loop already

    <?php if ( get_post_meta($post->ID, 'votes', true) ) {
        $author_vote_count = $author_vote_count + get_post_meta($post->ID, 'votes', true);
    } ?>

<?php endwhile; ?>

<?php echo "Total votes on author's posts: " . $author_vote_count; ?>

The above will only work as expected, if the meta_value of the key votes is an integer (or any type of number). Should it be saved in the database as a string, you need to convert it to an integer first. In that case use

$author_vote_count = $author_vote_count + intval( get_post_meta($post->ID, 'votes', true) );

instead.

Related Posts:

  1. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  2. using multiple meta_key and meta_value in query_posts
  3. How can I sort homepage by a meta value?
  4. meta_compare seems to be treating values as strings instead of integers as expected
  5. Unable to get specific value from post meta
  6. wordpress multi user question
  7. How can I change author of posts to the value of one of the custom field of the posts?
  8. Custom query with orderby meta_value of custom field
  9. what is the correct way to compare dates in a WP query_posts meta_query
  10. Can I exclude a post by meta key using pre_get_posts function?
  11. Custom post meta field effect on the performance on the post
  12. How to get custom post meta using REST API
  13. Difference between meta keys with _ and without _ [duplicate]
  14. Orderby meta_value only returns posts that have existing meta_key
  15. What is the index [0] for on post meta fields?
  16. What is “meta_input” parameter in wp_insert_post() used for?
  17. Query Posts or Get Posts by custom fields, possible?
  18. How to enable revisions for post meta data?
  19. The “_encloseme” Meta-Key Conundrum
  20. Best way to programmatically remove a category/term from a post
  21. Using get_post_meta with new_to_publish
  22. Custom field metabox not showing in back-end
  23. So much data in postmeta
  24. Can I count the number of users matching a value in a multiple value key?
  25. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  26. How to hide meta box values from custom fields list?
  27. Auto sort the wp-admin post list by a meta key
  28. get_post_meta() unserialize issue – returns boolean(false)
  29. What is the advantage of the wp_options design pattern?
  30. Storing meta fields multiple times OR once with multi dimensional array?
  31. Allow user to create instances of custom field
  32. query_posts and only show results if a custom field is not empty
  33. display specific custom fields
  34. Filter archive.php by custom meta
  35. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  36. Meta keywords and descriptions plugin for manually editing meta for each page/post
  37. passing argument to get_template_part() or a better way to code
  38. Is it possible to store arrays in a custom field?
  39. Get updated meta data after save_post hook
  40. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  41. Save HTML formatted data to post meta using add_post_meta()
  42. importing data from non-wordpress mysql db
  43. Order posts by custom field and if custom field is empty return remaining posts
  44. Create meta boxes that don’t show in custom fields
  45. Transients vs CRON +Custom Fields: Caching Data Per Post
  46. Unable to save datetime custom meta field using update_post_meta() function
  47. Up/Down voting system for WordPress
  48. Guest Author – How can I use custom fields to create guest author link?
  49. post meta data clearing on autosave
  50. Create custom field on post draft or publish?
  51. Display info from custom fields in all images’ HTML
  52. Ordering posts by anniversary using only day and month
  53. get_post_meta fields don’t show up on posts page
  54. Update meta values with AJAX
  55. Query on custom field count?
  56. How to break meta values into different items and avoid duplicates?
  57. copy attachments to another post type and change attachment url
  58. Cannot edit post meta fields with rest API
  59. ajax delete value from custom field array
  60. Save attachment custom fields on front end
  61. How to use pagination with get_post_meta
  62. Copying Custom Meta Values from existing post to a duplicate post
  63. How to use query_posts() with a date filter on a custom field?
  64. Add a post meta key and value only if it does not exist on the post
  65. Move value of one custom field to another
  66. Order posts according to user defined order for meta values?
  67. Displaying posts with only upcoming dates according their custom field date value
  68. Custom fields to save multiple values
  69. Custom fields: In what order are they saved into the DB?
  70. Function to change meta value in database for each post
  71. Get a post_id where meta_value equals something in a serialized meta_value field
  72. Get aggregate list of all custom fields for entire blog
  73. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  74. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  75. Custom field value based on other custom field values
  76. meta_value_num sort glitch
  77. Can ordering post list by meta_value cause performance issue?
  78. Order by value in serialized custom field
  79. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  80. How to save a ToggleControl value in a meta field?
  81. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  82. Saving custom image meta fields
  83. How do I query for a post by custom field?
  84. meta query not showing any results?
  85. How to display Meta Field Value?
  86. MySQL query to set wp_postmeta using term_taxonomy_id value
  87. How to Validate Post Meta type/extension (Video File Image File etc)
  88. Get all meta keys assigned to a post type
  89. how can i use custom field in query post
  90. Custom Meta Box not Saving in Posts with Gutenberg Editor
  91. Query post order by post and desc not working
  92. Adding custom fields (post meta) before/during wp_insert_post()
  93. Combine multiple custom field values into single value
  94. Get specific custom field keys from a post and put into an array
  95. How do I use wp_query for WordPress search?
  96. Nav Menu – Add class based on meta keys
  97. How to query posts with certain custom meta data, and output Post data
  98. MySQL Query that looks for post with Custom Field, then changes Category
  99. Order query by meta_value with multiple custom fields
  100. ACF: How to get the full field name (meta_key) by a field key?
Categories custom-field Tags author, custom-field, post-meta, query-posts
Efficient way to fetch all archived WPMS blogs
I need advice on how to structure the categories according to the layout i have

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