WordPress.org

Ready to get started?Download WordPress

Forums

How to update datebase? (1 post)

  1. webviewer
    Member
    Posted 1 year ago #

    I want to count the number that how many people visited my post.My code is following:
    function post_viewnum(){
    global $wpdb;
    $postid=$post->ID;
    $postviewnum=$wpdb->get_var("SELECT viewnum FROM wp_posts WHERE ID='$postid'");
    $postviewnum=$postviewnum+1;
    $wpdb->query("UPDATE wp_posts SET viewnum='{$postviewnum}' Where ID='$postid'");
    echo $postviewnum;
    }
    The trouble is i can't get the viewnum,and can't update its datebase.

Topic Closed

This topic has been closed to new replies.

About this Topic