Forums

A standalone PHP pgm i wrote fails to access $wpdb (1 post)

  1. rnewton27410
    Member
    Posted 10 months ago #

    How to access $wpdb class in my PHP program so I can read wp_post table.
    Getting msg: Fatal error: Call to a member function get_row() on a non-object in /hermes/web09d/b483/moo.rnewtonnet/wordpress/RN-read.php on line 13.
    ============================================
    <?php
    /*
    include_once('wp-config.php');
    include_once('wp-load.php');
    include_once('/hermes/web09d/b483/moo.rnewtonnet/wordpress/wp-includes/wp-db.php');
    include_once('wp-blog-header.php');

    read from wp-posts table
    */
    global $wpdb;
    $mylink = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = 23, ARRAY_A");
    /*
    wp-posts table contents
    */
    echo "ID: ".$mylink['ID']."
    ";
    echo "post_author: ".$mylink['post_author']."
    ";
    echo "post_date: ".$mylink['post_date']."
    ";
    echo "post_date_gmt: ".$mylink['post_date_gmt']."
    ";
    echo "post_content: ".$mylink['post_content']."
    ";
    echo "post_title: ".$mylink['post_title']."
    ";
    echo "post_excerpt: ".$mylink['post_excerpt']."
    ";
    echo "post_status: ".$mylink['post_status']."
    ";
    echo "comment_status: ".$mylink['comment_status']."
    ";
    echo "ping_status: ".$mylink['ping_status']."
    ";
    echo "post_password: ".$mylink['post_password']."
    ";
    echo "post_name: ".$mylink['post_name']."
    ";
    echo "to_ping: ".$mylink['to_ping']."
    ";
    echo "pinged: ".$mylink['pinged']."
    ";
    echo "post_modified: ".$mylink['post_modified']."
    ";
    echo "post_modified_gmt: ".$mylink['post_modified_gmt']."
    ";
    echo "post_content_filtered: ".$mylink['post_content_filtered']."
    ";
    echo "post_parent: ".$mylink['post_parent']."
    ";
    echo "guid: ".$mylink['guid']."
    ";
    echo "menu_order: ".$mylink['menu_order']."
    ";
    echo "post_type: ".$mylink['post_type']."
    ";
    echo "post_mime_type: ".$mylink['post_mime_type']."
    ";
    echo "comment_count: ".$mylink['comment_count']."
    ";
    ?>
    =============
    Obviously, I don't understand how to invoke $wpdb class.

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 10 months ago by rnewton27410
  • This topic is not resolved
  • WordPress version: 3.2.1

Tags