Documentation

Add

int
CBlogPost::Add(
 array arFields
);

The method adds new blog post. Non-static method.

Method parameters

ParameterDescription
arFields Array of the array("field"=>"value"[, ...]) type, containing values of the blog post fields.

Also, separate level of access permissions can be specified for blog posts and comments. To do this, array of the array("PERMS_POST" => array("userGroupID" => "Permission"[, ...]), "PERMS_COMMENT" => array("userGroupID" => "Permission"[, ...])) type must be created, where userGroupID - blog users group Permission - level of access permissions.

Returned value

The method returns ID of added blog post, if the adding was successful. When an error occurs, the method will return false, and exceptions will contain errors.

See Also

Examples of use

<?
$CATEGORY_ID = CBlogCategory::Add(array("BLOG_ID" => 1,"NAME" => 'Category 1'));
$arFields = array(
    "TITLE" => 'My first post in the blog',
    "DETAIL_TEXT" => 'Text of my first blog post',
    "BLOG_ID" => 1,
    "AUTHOR_ID" => $USER->GetID,
    "=DATE_CREATE" => $DB->GetNowFunction(),
    "DATE_PUBLISH" => '15.08.2007 9:40',
    "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH,
    "ENABLE_TRACKBACK" => 'N',
    "ENABLE_COMMENTS" => 'Y',
    "CATEGORY_ID" => $CATEGORY_ID,
    "PERMS_P" => Array("1" => BLOG_PERMS_READ, "2" => BLOG_PERMS_READ),
    "PERMS_C" => Array("1" => BLOG_PERMS_READ, "2" => BLOG_PERMS_WRITE)
);
$newID = CBlogPost::Add($arFields);
if(IntVal($newID)>0)
{
    foreach($CATEGORY_ID as $v)
        CBlogPostCategory::Add(Array("BLOG_ID" => 1, "POST_ID" => $newID, "CATEGORY_ID"=>$v));
    echo "New blog post [".$newID."] is added.";
}
else
{
    if ($ex = $APPLICATION->GetException())
        echo $ex->GetString();
}
?>


© «Bitrix24», 2001-2023
Up