LLMS_Post_Handler::create( string $type = 'post', string $title = '',  $excerpt = '' )

Create Post


Description Description


Parameters Parameters

$type

(string) (Optional) [optional: a post type]

Default value: 'post'

$title

(string) (Optional) [optional: a title for the post]

Default value: ''


Top ↑

Return Return

(int) [id of section]


Top ↑

Source Source

File: includes/class.llms.post.handler.php

	public static function create( $type = 'post', $title = '', $excerpt = '' ) {

		if ( empty( $title ) ) {
			$title = 'Section 1';
		}

		// create section post
		$post_data = apply_filters( 'lifterlms_new_post', array(
			'post_type'     => $type,
			'post_title'    => $title,
			'post_status'   => 'publish',
			'post_author'   => get_current_user_id(),
			'post_excerpt'  => $excerpt,
		) );

		$post_id = wp_insert_post( $post_data, true );

		//check for error in update
		if ( is_wp_error( $post_id ) ) {
			//for now just log the error and set $post_id to 0 (false)
			llms_log( $post_id->get_error_message() );
			$post_id = 0;
		}

		return $post_id;

	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: