WordPress.org

Ready to get started?Download WordPress

Forums

Problem when include wordpress page in external website (2 posts)

  1. mansi37
    Member
    Posted 1 year ago #

    Hello,

    I want to get the total number of posts from wordpress to my php website.
    So i use line require_once('c:/xampp/htdocs/wordpress/wp-blog-header.php');

    There was no problem when I connected my database using "mysql_"

    But the problem arrives when I change the database connection string from "mysql_" to "PDO".

    I get Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'WORDPRESS_DB.MY_TABLE' doesn't exist

    So In my website, instead of my connection string, it uses the wordpress databse connection string.

    Please reply. How to solve this problem?
    Thanks.

  2. bcworkz
    Member
    Posted 1 year ago #

    If all you want is a post count, I would not load the WP environment with wp-blog-header.php. That is a lot of overhead for a mere post count.

    Instead, connect to the WP database with PDO and run a count query on the posts table for records of post_type = 'post' AND post_status = 'publish'

Topic Closed

This topic has been closed to new replies.

About this Topic