• Resolved seregawaw

    (@seregawaw)


    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://ww.wp.xz.cn/plugins/google-analytics-top-posts-widget/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Justin Sternberg

    (@jtsternberg)

    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

    (@seregawaw)

    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.