I want to create a video gallery plugin. I am using this code to create a post:

global $user_ID;
$new_post = array(
    'post_title'    => 'chapter1',
    'post_content'  => 'Lorem ipsum dolor sit amet...',
    'post_status'   => 'publish',
    'post_date'     => date( 'Y-m-d H:i:s' ),
    'post_author'   => $user_ID,
    'post_type'     => 'post',
    'post_category' => array(0)
$post_id = wp_insert_post( $new_post );

It's working well, but the problem is the created post shows in the admin dashboard "All Posts" panel; I don't want to show programmatically created posts there, or in the latest posts.

Is there any way I can do this? I tried to change the post type, but the generated post link gives me a page not found error.

  • 1
    did you change post type to a registered type? – Milo Mar 27 '15 at 7:21
  • Remember to flush your permalinks after you have registered your post type, otherwise you will get a 404 error – Pieter Goosen Mar 27 '15 at 7:35
  • i have little bit idea about permalink.. how can i flush permalinks. i am using /%postname%/ type permlinks – Allex Mar 27 '15 at 8:48
  • Just visit the permalink setting page in the back end, that is all. You can also, just for extra pleasure, click on the update button on that page. This will eset and resave all your permalinks – Pieter Goosen Mar 27 '15 at 8:52

And to create a custom post type is not an option?

'post_type' => 'custom_post_type'

then just hide the custom post type from the UI

see Possible to hide Custom Post Type UI/Menu from specific User Roles?

  • how can i create custom post type. i have plugin installed in my word press website "WORDPRESS VIDEO GALLERY" it uses custom post type "videogallery" i want to make similar one like that – Allex Mar 27 '15 at 17:26

Edit: I thought this would be fairly simple but seems I'm just not competent enough.

You could get around it by adding an arbitrary category (like my_prog_cat_to_hide) for these programmatically added posts and then filtering them out in the admin listing.

function wpse182434_get_category_id($cat_name){
    $term = get_term_by('name', $cat_name, 'category');
    return $term->term_id;

function wpse182434_filter_admin_query( $query ) {
    if(is_admin() && $query->is_main_query() && !filter_input(INPUT_GET, 'post_status') && ( $screen = get_current_screen() ) instanceof \WP_Screen && 'edit-post' === $screen->id) {
        $query->set( 'cat', '-'.wpse182434_get_category_id('my_prog_cat_to_hide') );
add_action( 'pre_get_posts', 'wpse182434_filter_admin_query' );

Of course this leaves you with handling stuff like not showing that category on the front end and/or in feeds and what not.

in that wpse182434_filter_admin_query the if conditions are so that if you select published or any other filter than all posts from the top, you still see the articles. They are just filtered out in the all posts listing.

And all this goes in your functions.php of course.

  • i know video gallery plugin which exactly do. what i want . its create video post , post type "videogallery" and not show in "AllPost" tab or in front end website in latest post section . i want to make similar one like that – Allex Mar 27 '15 at 17:31
  • Well that's basically what I was suggesting before. I think you could do this via custom post type with custom post status. – jimihenrik Mar 27 '15 at 17:49
  • i am using "Custom Post Type UI" for creating custom post type and using php code to create post now its adding custom post type name before post name example "/customposttype/mypostcreatebyphp/" but it still give me page not found error – Allex Mar 27 '15 at 18:24
  • thanks for help and tips. i did it as you all mentioned in comments . by using "Custom Post Type UI" and php create post code. after that i have to only flush the permalinks and its working .. thank you again . – Allex Mar 27 '15 at 18:27
  • Awesome if you got it working. – jimihenrik Mar 27 '15 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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