Title: php shortcode google_analytics_views
Last modified: August 30, 2016

---

# php shortcode google_analytics_views

 *  Resolved [seregawaw](https://wordpress.org/support/users/seregawaw/)
 * (@seregawaw)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/php-shortcode-google_analytics_views/)
 * How can I copy a value shortcode `[google_analytics_views]` in any field?
 * Work example plugin “Google Analytics Dashboard”
 *     ```
       $data        = new GADWidgetData();
           $views       = $data->gad_pageviews_text($id);
   
           if ($views !== '') {
             if (get_post_meta($postid, 'views', FALSE)) {
               update_post_meta($postid, 'views', $views);
             } else {
               add_post_meta($postid, 'views', $views);
             }
           };
       ```
   
 * [https://wordpress.org/plugins/google-analytics-top-posts-widget/](https://wordpress.org/plugins/google-analytics-top-posts-widget/)

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

 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/php-shortcode-google_analytics_views/#post-6378983)
 * I’m not sure why you would want to get the value and store to post-meta (as the
   value is already cached, and if you store it to post-meta, it will be frozen 
   in time), but you can get the view count this way:
 *     ```
       $atts = array(
       	'post_id'    => get_the_ID(),
       	'start_date' => date( 'Y-m-d', time() - ( DAY_IN_SECONDS * 30 ) ), // 30 days ago
       	'end_date'   => date( 'Y-m-d' ), // today
       );
       GA_Top_Content::get_instance()->views_shortcode( $atts, null );
       ```
   
 *  Thread Starter [seregawaw](https://wordpress.org/support/users/seregawaw/)
 * (@seregawaw)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/php-shortcode-google_analytics_views/#post-6378995)
 * Thank you, it works! The value of custom fields I use to sort the records in 
   the category.

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

The topic ‘php shortcode google_analytics_views’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/google-analytics-top-posts-widget.
   svg)
 * [Google Analytics Top Content Widget](https://wordpress.org/plugins/google-analytics-top-posts-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-analytics-top-posts-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-analytics-top-posts-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/google-analytics-top-posts-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-analytics-top-posts-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-analytics-top-posts-widget/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [seregawaw](https://wordpress.org/support/users/seregawaw/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/php-shortcode-google_analytics_views/#post-6378995)
 * Status: resolved