Title: meta_key from mysql database
Last modified: August 20, 2016

---

# meta_key from mysql database

 *  [hany88](https://wordpress.org/support/users/hany88/)
 * (@hany88)
 * [14 years ago](https://wordpress.org/support/topic/meta_key-from-mysql-database/)
 * I have the plugin “WTI Like Post” installed and its working. But I’m missing 
   a feature to order the posts by the like count.
    In wti_like_post.php I found
   the code to query the mysql database for the like count:
 *     ```
       function GetWtiLikeCount($post_id) {
            global $wpdb;
            $show_symbols = get_option('wti_like_post_show_symbols');
            $wti_like_count = $wpdb->get_var("SELECT SUM(value) FROM {$wpdb->prefix}wti_like_post WHERE post_id = '$post_id' AND value >= 0");
       [...]
            return $wti_like_count;
       }
       ```
   
 * Under the table “wti_like_post” there is a column “value” which stores int values(
   the like count which I need as a meta_key).
 * What I want to do: On a specific_page.php I want to loop through the posts and
   order them by the like count. I think I should use a meta_key, but how can I 
   define “value” from the mysql connection as a meta_key ?
 * So what I want to do is:
 *     ```
       $likes = // Get_the_meta_key_from_mysql_somehow
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
   
       $args= array('meta_key' => $likes,
                    'orderby' => 'meta_key_num',
                    'paged' => $paged
       );
       query_posts($args);
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [hany88](https://wordpress.org/support/users/hany88/)
 * (@hany88)
 * [14 years ago](https://wordpress.org/support/topic/meta_key-from-mysql-database/#post-2702688)
 * maybe I’m mixing something up here.
 * This is what I want:
 * Under the table “wti_like_post” I have a column “value” and “post_id” which stores
   int values (like count) for a specific post (post_id). I don’t have custom fields.
 *     ```
       mysql> select id,post_id,value from wp_wti_like_post;
       +----+---------+-------+
       | id | post_id | value |
       +----+---------+-------+
       |  1 |      26 |     1 |
       |  2 |      24 |     3 |
       |  3 |      26 |     5 |
       |  4 |      22 |     9 |
       +----+---------+-------+
       ```
   
 * I want to make a new page where the posts are ordered by the “value”. How can
   I dot his?
 *  [webtechideas](https://wordpress.org/support/users/webtechideas/)
 * (@webtechideas)
 * [14 years ago](https://wordpress.org/support/topic/meta_key-from-mysql-database/#post-2702840)
 * please follow this link [http://wordpress.org/support/topic/plugin-wti-like-post-most-voted-post-list?replies=2](http://wordpress.org/support/topic/plugin-wti-like-post-most-voted-post-list?replies=2)
   you can download the manual present on the given link for more reference.
 * This will create a page with list of most liked posts. But as per your 1st question,
   it seems more likely that you want to do this on default wordpress page.php which
   is not possible as of now since these like counts are not stored as post meta
   values.
 * Let me know if this helped you or not.
 *  Thread Starter [hany88](https://wordpress.org/support/users/hany88/)
 * (@hany88)
 * [14 years ago](https://wordpress.org/support/topic/meta_key-from-mysql-database/#post-2702932)
 * Thanks for the answer.
    I thought if it’s possible to show a most-liked-post 
   list with [most_liked_posts limit=”X” time=”Y”] it should also be possible to
   show the corresponding post. Isn’t there a function I can use in my custom_page.
   php ?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘meta_key from mysql database’ is closed to new replies.

## Tags

 * [meta_key](https://wordpress.org/support/topic-tag/meta_key/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 2 participants
 * Last reply from: [hany88](https://wordpress.org/support/users/hany88/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/meta_key-from-mysql-database/#post-2702932)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
