MAINTENANCE RELEASE EasyBlog 5.3.4 is now available! Learn more about EasyBlog 5.3.4 ✨

Helpdesk

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;
}

This section can only be seen by users with a valid subscription.
If you have a valid subscription, please login now

Your time
Stack Ideas HQ
Support is
Offline

It is currently off working hours and most of us aren't around.

Rest assured that we will get back to your issues as soon as the day starts tomorrow!

Subscribe for product updates & promotions