Dominic Fagan
Dominic Fagan

Reputation: 151

Wordpress - "Unknown post type" when editing

I wrote a script to add new entries into my "interactions" post type, but they don't come up in interactions, and when I manually point my browser to the ID of the post in the editor, it tells me "Unknown post type".

Heres the code I added the post with:

            $new_post = array(
            'post_title' => $title,
            'post_content' => '',
            'post_status' => 'publish',
            'post_date' => date('Y-m-d H:i:s'),
            'post_author' => '',
            'post_type' => 'interaction'
        );

        $id = wp_insert_post($new_post);``

The post is being created but the new entries don't show up on the interactions list and I can't edit it because it tells me its an unknown post type.

What could be causing this issue?

Upvotes: 1

Views: 323

Answers (1)

MrZiggyStardust
MrZiggyStardust

Reputation: 733

You have an typo in your post_type parameter. Change it to: interactions instead of interaction

<?php
$new_post = array(
    'post_title' => $title,
    'post_content' => '',
    'post_status' => 'publish',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => '',
    'post_type' => 'interactions'
);

$id = wp_insert_post($new_post);

Upvotes: 1

Related Questions