0

I have a custom function to count downloaded times for a specific file attached in the post, but i want to display the count of whole post in my website

post meta = download_times

and how to skip time out error message ?

4
  • I have a custom function to count downloaded times for a specific file attached in the post - Is this function working?
    – prosti
    Commented Jan 10, 2017 at 18:14
  • the function works and it counts the file downloaded and updates the post meta for each post , but i want to count all post meta values to get the total downloaded from all posts !
    – wassimo
    Commented Jan 10, 2017 at 19:14
  • You can adopt this answer: wordpress.stackexchange.com/questions/237610/… from @TomJNowell
    – prosti
    Commented Jan 10, 2017 at 19:23
  • If you have any problems just let me know.
    – prosti
    Commented Jan 10, 2017 at 19:24

1 Answer 1

1

Thank You @prosti for your answer I made Thise small code based on your answer and it works for me

global $post;
$query_args = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'order' => 'DESC',
            'posts_per_page' => -1,
            'cat' => 1,
            // 'fields' => 'SUM(amount_to_paid)',
        );

$sum = 0;
$query = new WP_Query($query_args);
if ( $query->have_posts() ) {
    while( $query->have_posts() ) {
        $query->the_post();
        // do the processing for each post
        $sum = $sum + intval(get_post_meta(get_the_id(),'download_counter' ));
    }
}
echo $sum ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.