0

I want to create a post type but don't allow to create new item on the back-end, the item of this post type can be only created on the front-end by the user. How can I do this?

Thank you

3
  • you're aware comments can have meta/custom fields etc?Could you provide some context as to why you want/need this and what you're trying to achieve?
    – Tom J Nowell
    Mar 28, 2013 at 22:11
  • @TomJNowell , I want my register can create some items, but admin(back-end) can't add / delete these items, and I also need the custom field feature for my custom post type, is this enough?
    – aserww106
    Mar 28, 2013 at 23:22
  • That doesn't actually answer my question, you've just said what you've already said in your question. Nowhere did you say why?
    – Tom J Nowell
    Mar 28, 2013 at 23:39

2 Answers 2

0

You can set show_ui to false in register_post_type arguments

You can create a "post" in the front-end using wp_insert_post

1
  • I want admin can see it on the back-end, but can't add or delete or change them, thank you!
    – aserww106
    Mar 28, 2013 at 23:24
0

Any post type can be created on the frontend, but you will need to write the form, and the save logic.

When you have submitted your form and have your content/title/etc prepared in variables, pass them into this function

wp_insert_post( $post, $wp_error );

e.g.

// Create post object
$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_type'     => 'post',
  'post_status'   => 'publish',
  'post_author'   => 1,
);

// Insert the post into the database
$new_post_id = wp_insert_post( $my_post );

By looking at the codex page and using some common sense you can create any type of post. These are the same APIs used by the admin dashboard code

To hide it in the backend, set show_ui to false when calling register_post_type

4
  • I want admin can see these items at back-end, but can't create or change or delete them. how can I do this? thank you!
    – aserww106
    Mar 28, 2013 at 23:26
  • Why? What happens if someone makes a post with "videos of incestuous rape between children using crucifixes while standing on a picture of people throwing shoes at the prophet mohammed wearing Nazi costumes", wouldn't you want an admin to be able to delete it?
    – Tom J Nowell
    Mar 28, 2013 at 23:42
  • Yes, I definitely want to delete those kinds of content on my web site.
    – aserww106
    Mar 29, 2013 at 2:43
  • Then the question is how? Can you please, explain why?
    – Tom J Nowell
    Mar 29, 2013 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.