[wp-trac] [WordPress Trac] #28135: wp_insert_post returns error for custom post type in 3.9.0

WordPress Trac noreply at wordpress.org
Mon May 5 12:50:44 UTC 2014


#28135: wp_insert_post returns error for custom post type in 3.9.0
-------------------------------+-----------------------------
 Reporter:  capit0l            |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  3.9
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 I'm trying to insert post for custom post type by function wp_insert_post
 it returns error. But functions still works, post is added to database.

 This is my code:

 {{{
 $current_user = wp_get_current_user();
 $name = $_REQUEST['paymetn_m_name'] . ' ' . $_REQUEST['paymetn_m_sname'];

 $post = array(
     'post_title' => $name,
     'post_type' => 'orders',
     'post_status' => 'publish',
     'post_author' => $current_user->ID
 );

 wp_insert_post( $post );
 }}}

 This is error:


 '''Notice: Trying to get property of non-object in
 /Users/capit0l/Sites/technostore/wp-includes/post.php on line 2187
 Notice: Trying to get property of non-object in
 /Users/capit0l/Sites/technostore/wp-includes/post.php on line 2187
 '''

 Problem is in this function:
 {{{
 function _count_posts_cache_key( $type = 'post', $perm = '' ) {
         $cache_key = 'posts-' . $type;
         if ( 'readable' == $perm && is_user_logged_in() ) {
                 $post_type_object = get_post_type_object( $type );
                 if ( ! current_user_can(
 $post_type_object->cap->read_private_posts ) ) {
                         $cache_key .= '_' . $perm . '_' .
 get_current_user_id();
                 }
         }
         return $cache_key;
 }

 }}}

 As a temporary solution I added @ in front of wp_insert_post function.

 For extra information, i'm using OS X 10.9.2, PHP Version 5.4.24.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28135>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list