Retrieve values from WordPress database
-
I want to display values from sql query next to a single post.
This is the function I use:add_action('show_etiqueta','et_get_post_user_etiqueta'); function et_get_post_user_etiqueta( $post_id ){ global $wpdb; $result = $wpdb->get_results($wpdb->prepare("SELECT meta_value, count(*) AS countof FROM $wpdb->commentmeta WHERE meta_key='et_comment_etiqueta' GROUP BY meta_value ORDER BY countof DESC LIMIT 5", $post_id)); print_r($result); return $result; }
I call it here:
<?php do_action( 'show_etiqueta' ); ?>
But all I get as output is this:
Array ( [0] => stdClass Object ( [meta_value] => test [countof] => 3 ) [1] => stdClass Object ( [meta_value] => inprediscible [countof] => 1 ) [2] => stdClass Object ( [meta_value] => interesante [countof] => 1 ) [3] => stdClass Object ( [meta_value] => aqui va tu etiqueta [countof] => 1 ) [4] => stdClass Object ( [meta_value] => hurtest [countof] => 1 ) )
I tested the query in phpmyadmin to see if I get the result I want and it really gets the right result.
Can Anyone help me to have the right result displayed? tHank you
- The topic ‘Retrieve values from WordPress database’ is closed to new replies.