By Christopher Ambler on Friday, 18 October 2019
Posted in Technical Issues
Likes 0
Views 774
Votes 0
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;
}
You can try take a look my attached file sample code.
·
Friday, 18 October 2019 12:27
·
0 Likes
·
0 Votes
·
0 Comments
·
That works!

You rock!

Thank you very much!
·
Saturday, 19 October 2019 04:58
·
0 Likes
·
0 Votes
·
0 Comments
·
You are welcome.

Just for your information, I have locked and marked this thread as resolved to avoid confusions in the future. Please start a new thread if you have any other issue in the future so it will be easier for us to manage your inquiries.

Thanks for understanding.
·
Saturday, 19 October 2019 08:57
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post