Title: function   shortcode to create plugin : latest comments meta_value
Last modified: August 20, 2016

---

# function shortcode to create plugin : latest comments meta_value

 *  [coxine](https://wordpress.org/support/users/coxine/)
 * (@coxine)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/function-shortcode-for-a-specific-query/)
 * Hi everybody
    I’m looking for help to create a shortcode which calls specific
   field from commentmeta – meta_value.
 * Here is the sql query :
 *     ```
       <? $select = "SELECT meta_value FROM " . "$wpdb->commentmeta WHERE meta_key='pmg_comment_title' AND meta_value!=''";
       		$requete = $wpdb->get_results($select);
       		foreach($requete as $ligne){?>
   
       		<?php echo $ligne->meta_value; echo'<br/>';
       		}
       		?>
       ```
   
 * The begining of the fucntion should be ?
 *     ```
       function MYshorcode_shortcode( $atts )
       {
       /// I don't know how to call sql
       add_shortcode('MYshortcode', 'MYshortcode_shortcode');
       ```
   
 * I’m newbie in WP hack, so I don’t understand how to create a function then a 
   shortcode to make the query works in a widget.
 * I’ve also add to my function.php file :
    `add_filter('widget_text', 'do_shortcode');`
 * Thank’s for your help !
 * (excuse my bad english ;))

The topic ‘function shortcode to create plugin : latest comments meta_value’ is 
closed to new replies.

## Tags

 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [coxine](https://wordpress.org/support/users/coxine/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/function-shortcode-for-a-specific-query/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
