Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ...Call the database connection settings
- require( path to /wp-config.php );
- // ...Connect to WP database
- $dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
- if ( !$dbc ) {
- die( 'Not Connected: ' . mysql_error());
- }
- // Select the database
- $db = mysql_select_db(DB_NAME);
- if (!$db) {
- echo "There is no database: " . $db;
- }
- // ...Formulate the query
- $query = "
- SELECT *
- FROM `wp_posts`
- WHERE `post_status` = 'publish'
- AND `post_password` = ''
- AND `post_type` = 'post'
- ";
- // ...Perform the query
- $result = mysql_query( $query );
- // ...Check results of the query and terminate the script if invalid results
- if ( !$result ) {
- $message = '<p>Invalid query.</p>' . "\n";
- $message .= '<p>Whole query: ' . $query ."</p> \n";
- die ( $message );
- }
- // Init a variable for the number of rows of results
- $num_rows = mysql_num_rows( $result );
- // Print the number of posts
- echo "$num_rows Posts";
- // Free the resources associated with the result set
- if ( $result ) {
- mysql_free_result( $result );
- mysql_close();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement