• 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

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘wp_insert_post not return post id’ is closed to new replies.