• I modified one of the import scripts to pull in my text-file database. Everything works, except for the categories. My blog has 4 categories:
    3 FAQ
    1 General
    4 News
    2 Recipe
    I want all the imported posts to show up as Category 2. In my PERL code, I have this:
    $category = 2; (I also tried $category = “$2”;)
    Each time, the INSERT succeeds, but when I look at the story, I get an error message:
    Filed under:
    Warning: Invalid argument supplied for foreach() in /home/.callahan/mfischer/foo/wp-includes/template-functions-category.php on line 65
    � @ 8:08 am Edit This
    I can fix it with a manual edit, but I want to know, what is supposed to go here???
    (Here is my SQL):
    $mlf_query = “INSERT INTO wp_posts (post_author, post_date, post_content, post_title, post_category, post_name, post_status, comment_status) VALUES (‘$author’, ‘$posted’, ‘$content’, ‘$title’, ‘$category’, ‘$post_name’, ‘publish’, ‘
    open’)”;

Viewing 6 replies - 1 through 6 (of 6 total)
  • My guess is that wp is trying to get all the posts in cat#1, and as there are none, it borks.
    Try putting a post into cat id#1 ?

    Thread Starter mfischer2

    (@mfischer2)

    I think you are referring to the bug where “each category must have a post”. That is already the case, I have 1 post (at least) in each category.
    My categories display fine…
    Categories:
    * General
    * Recipe
    * FAQ
    * News
    I think there is something in that SQL or the category number I am using that WP doesnt like very much.

    Thread Starter mfischer2

    (@mfischer2)

    and in case thats not what you meant, I just tried an insert with $category = 1, and it has the same issue.

    Thread Starter mfischer2

    (@mfischer2)

    more updates from me.
    Using the mysql command line, I dumped the entry. The category was 1 and looked okay to me.
    mysql> select post_category from wp_posts where id=15;
    +—————+
    | post_category |
    +—————+
    | 1 |
    +—————+
    1 row in set (0.01 sec)
    compare this to a “valid” category…
    mysql> select post_category from wp_posts where id=13;
    +—————+
    | post_category |
    +—————+
    | 2 |
    +—————+
    1 row in set (0.00 sec)
    Looks pretty much the same (except for 1 vs 2). So I changed it in mysql…
    mysql> update wp_posts set post_category=2 where id=15;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1 Changed: 1 Warnings: 0
    This changed that number to 2, but still didnt fix the page.
    ———————————————————————————–
    One other possible hint, when I edit the entry with the defective category setting, it says “Warning: in_array(): Wrong datatype for second argument in /foobar/wp-admin/admin-functions.php on line 41.”
    Perhaps this means that the datatype PERL is giving to mysql is not correct?

    Thread Starter mfischer2

    (@mfischer2)

    Got it.
    I was not updating wp_post2cat. I will try that.

    Thread Starter mfischer2

    (@mfischer2)

    Awesome, it works. I will make a wiki entry soon about editing stuff with my SQL and PERL. Sorry Carthik, you told me about post2cat, but I didnt understand until I realized, “posts can be in multiple categories at once” which obviously implied that category was more than a simple integer!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘cannot insert record with proper category’ is closed to new replies.