countryCode; //check ip exists or not $row = $wpdb->get_row("SELECT * FROM counter WHERE ip='$user_ip'"); //if not than add count if($row==NULL){ $wpdb->insert( 'counter', array( 'ip' => $user_ip, 'country' => $usr_country ) ); } //making a widget //sql //SELECT country, count(country) AS "total" FROM counter AS A1 GROUP BY country / /** * Adds aa_counter widget. */ class aa_counter extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( 'aa_counter', // Base ID __('Visitor Counter', 'text_domain'), // Name array( 'description' => __( 'Visitor Counter', 'text_domain' ), ) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { echo $args['before_widget']; if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; } //widget global $wpdb; $row = $wpdb->get_results('SELECT country, count(country) AS "total" FROM counter AS A1 GROUP BY country '); if(is_array($row)){ echo "
options = get_option( 'my_option_name' ); ?>