• Resolved kriggins

    (@kriggins)


    Is there a quick and easy way to get the number of posts on a wordpress blog from outside of wordpress? I am aware of the internal count function, but I need to do some script based work outside of the wordpress framework based on the post count of my blog.

    I can mangle something up with php and sql, but just wanted to know if there was a ‘better’ way.

    Kevin

Viewing 4 replies - 1 through 4 (of 4 total)
  • Better then querying the database? No.

    Outside WordPress the most ideal way would be to count via MySQL query.

    SELECT COUNT(ID) as post_count FROM wp_posts WHERE .... etc..

    Would be the faster and most efficient (far more efficient than including all the necessary WordPress files just to get a post count).

    Thread Starter kriggins

    (@kriggins)

    Answered my own question.

    #!/usr/bin/php -q
    <?
    require( '/var/www/sbn/wp-load.php' );
    
    $count_posts = wp_count_posts();
    k
    $published_posts = $count_posts->publish;
    
    echo $published_posts;
    ?>
    Thread Starter kriggins

    (@kriggins)

    Thanks t31os_Moderator.

    By including wp-load.php you are in essence loading piles of WordPress functions just to do a simple count query.

    I was hinting at avoiding doing something like above, but if you’re happy with that solution then i’ll consider my work done here.. ??

    Of course to do a manual query you’d need to write some PHP and MySQL to query the database and if that’s beyond you (no problem there, we can’t all know code can we), then the above is probably the easy/quick solution you’re after.

    Happy to help anyway… ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get post count outside of wordpress’ is closed to new replies.