I am following your own code examples for creating a post in code. The problem is that the "image" field in the post data never accepts anything I give it. Clearly you do a bunch of processing on images before setting this field.
Since you support programmatic posting, would you please provide a code example on how to use this field? I can have the image uploaded and on a path, or I can provide a URL. Either is fine.
But I need to know how to set this to get a post cover image in the post via code, please.
$postdata['image'] = $image; // This line does nothing!
My code:
public static function Post($userid, $category, $categories, $image, $postType, $content, $permalink, $posttitle, $tags, $description, $keywords)
{
$author = JFactory::getUser($userid);
$post = EB:
ost(null, $author->id);
$createOptions = array('checkAcl' => false,
'overrideAuthorId' => $author->id);
try {
$post->create($createOptions);
}
catch (Exception $ex) {
echo "Failed to create post!
";
echo $ex->getMessage();
}
$postdata = array();
$postdata['uid'] = $post->uid;
$postdata['permalink'] = $permalink;
$postdata['title'] = $posttitle;
$postdata['tags'] = $tags;
$postdata['keywords'] = $keywords;
$postdata['description'] = $description;
$postdata['created_by'] = $author->id;
$postdata['created'] = EB::date()->toSql();
$postdata['modified'] = EB::date()->toSql();
$postdata['publish_up'] = EB::date()->toSql();
$postdata['source_id'] = 0;
$postdata['source_type'] = EASYBLOG_POST_SOURCE_SITEWIDE;
if ($postType == 'post') {
$postdata['published'] = EASYBLOG_POST_PUBLISHED;
}
else {
$postdata['published'] = EASYBLOG_POST_DRAFT;
}
$postdata['frontpage'] = 1;
$postdata['doctype'] = EASYBLOG_POST_DOCTYPE_LEGACY;
$postdata['posttype'] = EBLOG_MICROBLOG_EMAIL;
$postdata['send_notification_emails'] = 0;
$postdata['category_id'] = $category;
$postdata['categories'] = $categories;
$postdata['image'] = $image;
$postdata['content'] = $content;
$post->bind($postdata, array());
try {
$saveOptions = array(
'applyDateOffset' => false,
'validateData' => true,
'useAuthorAsRevisionOwner' => true
);
$post->save($saveOptions);
}
catch (Exception $exception) {
echo "There was an exception saving the post!
";
echo $exception->getMessage();
}
return $postdata;
}