WordPress.org

Ready to get started?Download WordPress

Forums

wp_insert_post not return post id (2 posts)

  1. Y.Y.
    Member
    Posted 1 year ago #

    I am using wp_insert_post to add page on plugin activation.
    Default wp_insert_post return page_id/post_id after create page/post.

    my problem is that it's not return page_id.

    my code is

    register_activation_hook( __FILE__, 'mytables_ll' );
    function mytables_ll()
    {
    	$post_id = -1;
    
    		$author_id = 1;
    		$title = 'page1';
    		$slug = 'page1';
    
    		if( null == get_page_by_title( $title ) )
    		{
    
    			$post_id = wp_insert_post(
    					array(
    							'comment_status'	=>	'closed',
    							'ping_status'		=>	'closed',
    							'post_author'		=>	 $author_id,
    							'post_name'		=>	 $slug,
    							'post_title'		=>	 $title,
    							'post_status'		=>	'publish',
    							'post_type'		=>	'page'
    					));
    
    			update_post_meta($post_id, '_wp_page_template', 'template-form1.php');
    
    		}
    }

    Anyone can help me what is problem.
    Thanks in advance

  2. Y.Y.
    Member
    Posted 1 year ago #

    any answer????????

Topic Closed

This topic has been closed to new replies.

About this Topic