Count posts and metavalues
-
Hi,
I would like to achieve the following:
1: Count number of posts within a post_type and taxonomy-term within a certain timeframe. (DONE)
2: Count a metavalue within the previous result and combine the results as one final return (NOT DONE)Code for no.1:
function antall_ta5_mnt($avdeling = ALL, $korr = '0', $mnt = 'm') { $posts = array( 'post_type' => 'ta5', 'numberposts' => -1, 'tax_query' => array( array( 'taxonomy' => 'ta5_avdeling', 'field' => 'slug', 'terms' => $avdeling ), ), 'date_query' => array( array( 'year' => date( 'Y' ), 'month' => date( $mnd ) -$korr, ), ), ); $actual_mnt = date('m'); $posts = get_posts($posts); $counted = count($posts); if(($counted < 1) && ($mnt > $actual_mnt)) { return NULL; } else { return $counted; } }
Partial code for no.2:
$query = "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'meta_deltakere'"; $words = $wpdb->get_results($query); if ($words) { foreach ($words as $word) { $meta = strip_tags($word->meta_value); $meta = explode(' ', $meta); $count = count($meta); $totalcount = $count; } } else { $totalcount = 0; }
As you can see, the second code does not talk with the first one…
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Count posts and metavalues’ is closed to new replies.