• sundrop

    (@sundrop)


    I adapted a PHP script to insert an RSS feed into a post. (I wanted the actual text, not something that would update when the RSS feed would update.)

    It works great and fine, except that the count of posts is not accurate. From my testing and deleting, some of the categories show a negative # of posts.

    Somehow when the php is inserting the post, the category count is not incrementing by one. Can anyone help me? Frankly, I’m a bit out of my league working with this.

    Below is the php code used to create the posts.

    # Build Query
    $query = “INSERT INTO $tableposts “
    . “(post_author, post_date, post_date_gmt, post_content, post_title, post_status, comment_status, ping_status, post_name, post_modified, post_modified_gmt) “
    . “VALUES “
    . “(” . $wp_userid . “, ‘” . $now . “‘, ‘” . $now_gmt . “‘, ‘” . addslashes($content) . “‘, ‘” . addslashes($wp_posttitle) . “‘, ‘publish’, ‘” . $wp_allowcomments . “‘, ‘” . $wp_allowpings . “‘, ‘” . $wp_postname . “‘, ‘” . $now . “‘, ‘” . $now_gmt . “‘);”;

    # Run Query
    $wpdb->query($query);

    # Get ID for category
    $post_ID = $wpdb->get_var(“SELECT ID FROM $tableposts ORDER BY ID DESC LIMIT 1”);

    # Build category query
    $query = “INSERT INTO $tablepost2cat “
    . “(post_id, category_id) “
    . “VALUES “
    . “(‘” . $post_ID . “‘, ‘” . $wp_catid . “‘);”;

    # Run Category Query
    $wpdb->query($query);

    I’d be grateful for any help. Thank you.

  • The topic ‘Inaccurate Category Count from PHP inserting posts’ is closed to new replies.