WordPress.org

Ready to get started?Download WordPress

Forums

Total number of posts (2 posts)

  1. royal
    Member
    Posted 8 years ago #

    I want to say something like:

    There are X number of posts in Y categories over the last Z months/years/days (but probably months).

    Any thoughts?

    Thanks

  2. Aleister
    Member
    Posted 8 years ago #

    I just wrote this up. You could stick it in a plugin if you like, or however you want to use it.

    function show_statistics_info() {

    global $wpdb, $table_prefix;

    // get number of posts
    $result = "SELECT COUNT(*) FROM {$table_prefix}posts WHERE post_status = 'publish'";
    $num_posts = $wpdb->get_var($result);

    // get number of categories
    $result = "SELECT COUNT(*) FROM {$table_prefix}categories";
    $num_cats = $wpdb->get_var($result);

    // get date of oldest post
    $last_post = $wpdb->get_results("
    SELECT post_date
    FROM {$table_prefix}posts
    WHERE post_status = 'publish'
    ORDER BY post_date ASC
    LIMIT 1
    ");

    // calculate dates
    $num_seconds = time() - strtotime($last_post[0]->post_date);

    $num_months = $num_days / (365/12); // approximate

    $num_months = round($num_months);

    echo "There are $num_posts number of posts in $num_cats categories over the last $num_months months.";

    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags