Support » Plugin: Kudos » How to display or list posts with most kudos

  • Some tips for people who have been asking about this. Feel free to correct and improve or consider as revisions for a future release…

    In your WP database kudos are stored under the postmeta table like any other custom field attached to WP content. The four row columns in postmeta used by kudos are:

    1. meta_id :: unique identifier for each kudo
    2. post_id :: the ID of the post to which the kudo is attached
    3. meta_key :: is the identifier/key _kudos
    4. meta_value :: the number of kudos attached to the post

    Every time a post gets its first kudo a row of these column fields will be populated in postmeta; if the kudo count goes to zero they disappear from the database.

    Note the leading underscore for the metakey (_kudos). This makes the kudos field hidden in WordPress. That means you can’t edit the kudo count directly in the custom fields for your posts within the post editor because _kudos does not show up in the list of custom fields. You also can’t use most plugins/widgets that are able to display posts ordered by the number of kudos they have because they don’t read hidden fields. A simple solution is to change the plugin code and rename any existing “_kudos” to “kudos.” Then you can manipulate kudos counts as any other public custom field. You can also use Justin Tadlock’s Query Posts, Query Wrangler, etc. to display posts sorted by their kudos with widgets and shortcodes.

    Another problem you may run into is non-numeric sorting of the kudos value so that instead of listing posts from greatest to least number of kudos (11,5,2,1) you get an alphanumeric sort (5,2,11,1) that will start messing things up for you with kudo counts greater than 9. Numeric sorting is not the default, and some plugins that handle postmeta fields seem to trip over this. (Maybe there is an issue with how meta_value is defined in the database?) A simple solution is to modify the plugin code to store only 4-digit values under meta_value where the kudos count is always padded (ltr_pad) with leading zeroes which are then stripped out (ltrim) prior to displaying them. (In a list of descending values 0001 is never ahead of 0011 whether the sort is numeric or alphanumeric.)

    https://wordpress.org/plugins/kudos/

  • The topic ‘How to display or list posts with most kudos’ is closed to new replies.