UPDATES EasyBlog 6.0.14 Released! Joomla 5.x and PHP 8.x compatible now!

Helpdesk

Your Time
Our Time
Response Time
24 — 48 hours
We strive to provide the fastest ever response possible. However, we are not super beings.

Allow at least 24 — 48 hours
  Support is online
Our support specialists is available now. We will attend to you as soon as we can.
  Support is online

Need to know how to set $data['image'] when creating post

Christopher Ambler · ·
6:39 AM Friday, 18 October 2019
Normal
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::post(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;
}
The replies under this section are restricted to logged in users or users with an active subscription with us