Skip to content

Instantly share code, notes, and snippets.

@AramZS
Last active September 5, 2015 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AramZS/d10fe64dc33fc9ffc2d8 to your computer and use it in GitHub Desktop.
Save AramZS/d10fe64dc33fc9ffc2d8 to your computer and use it in GitHub Desktop.
Test functions based on PF stats for collecting data
<?php
function pf_test_author_leaderboard(){
$c = 0;
$the_query = new WP_Query(
array(
'post_type' => 'post',
'nopaging' => true,
'no_found_rows' => true,
'cache_results' => false,
'posts_per_page' => -1,
'date_query' => array(
array(
'year' => 2015,
'month' => 8,
),
),
'meta_key' => pressforward_stats()->meta_author_key,
)
);
$authors = array();
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$authors = pressforward_stats()->shortcodes->set_author_into_leaderboard( get_the_ID(), $authors );
$c++;
endwhile;
wp_reset_postdata();
$s = pressforward_stats()->shortcodes->the_shortcode( 'pf_author_leaderboard', array( 'authors' => $authors ) );
else :
$s = pressforward_stats()->shortcodes->the_shortcode( 'read_nothing', array( 'days' => '30' ) );
endif;
pressforward_stats()->shortcodes->set_pf_transient('author_leader', $s);
return $s;
}
var_dump(pf_test_author_leaderboard());
<pre><?php
function pf_test_author_leaderboard(){
$c = 0;
$the_query = new WP_Query(
array(
'post_type' => 'post',
'nopaging' => true,
'no_found_rows' => true,
'cache_results' => false,
'posts_per_page' => -1,
'date_query' => array(
array(
'year' => 2015,
'month' => 8,
),
),
'meta_key' => pressforward_stats()->meta_key,
)
);
$array = array();
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$item_link = get_post_meta(get_the_ID(), 'item_link', true);
$url_parts = parse_url($item_link);
if (!empty($array[$url_parts['host']])){
$array[$url_parts['host']] = $array[$url_parts['host']]+1;
} else {
$array[$url_parts['host']] = 1;
}
endwhile;
var_dump($array); die();
wp_reset_postdata();
$s = pressforward_stats()->shortcodes->the_shortcode( 'pf_wordcount_last_thirty', array( 'word_count' => $wc, 'count' => $c, 'days' => '30' ) );
else :
$s = pressforward_stats()->shortcodes->the_shortcode( 'read_nothing', array( 'days' => '30' ) );
endif;
return $s;
}
var_dump(pf_test_author_leaderboard());
<?php
function pf_test_author_leaderboard(){
$c = 0;
$the_query = new WP_Query(
array(
'post_type' => 'post',
'nopaging' => true,
'no_found_rows' => true,
'cache_results' => false,
'posts_per_page' => -1,
'date_query' => array(
array(
'year' => 2015,
'month' => 8,
),
),
'meta_key' => pressforward_stats()->meta_key,
)
);
$authors = array();
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$content = get_post_field( 'post_content', get_the_ID() );
$word_count = str_word_count( strip_tags( $content ) );
$wc = $wc+$word_count;
$c++;
endwhile;
wp_reset_postdata();
$s = pressforward_stats()->shortcodes->the_shortcode( 'pf_wordcount_last_thirty', array( 'word_count' => $wc, 'count' => $c, 'days' => '30' ) );
else :
$s = pressforward_stats()->shortcodes->the_shortcode( 'read_nothing', array( 'days' => '30' ) );
endif;
return $s;
}
var_dump(pf_test_author_leaderboard());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment