By Christopher Ambler on Thursday, 22 October 2020
Posted in Technical Issues
Replies 5
Likes 0
Views 683
Votes 0
Let's make sure we're clear - posts made in code show up and act just like any other post made through the editor.

The difference is, if I go to a post, on the back-end, that I made in code, there are options *BOTH* to publish the post as well as update the post.

The post is clearly published, though, as it's available on the site (and the Facebook autopost even fired and worked), yet the publish button is there and live as if the post wasn't actually published.

So again - functionality seems correct, but for some reason, the system thinks the post isn't published so shows me the publish button.
Hi Christopher,

May I know what is a 'post made in code'? Can you provide us steps on how to create this type of post?
·
Thursday, 22 October 2020 12:06
·
0 Likes
·
0 Votes
·
0 Comments
·
Sure. Based on guidance posted elsewhere on this board -


public static function Post($userid, $category, $categories, $image, $postType,
$content, $introContent, $permalink, $posttitle,
$tags, $description, $keywords): array
{
$author = Factory::getUser($userid);

$post = EB::post(null, $author->id);

$createOptions = array('checkAcl' => false,
'overrideDoctType' => 'legacy',
'overrideAuthorId' => $author->id);

try {

$post->create($createOptions);
}
catch (Exception $ex) {

echo "Failed to create post!<br /><br />";

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()->toMySQL();
$postdata['modified'] = EB::date()->toMySQL();
$postdata['publish_up'] = EB::date()->toMySQL();
$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;

$dlimage = self::downloadImage($image, $postdata);

if ($dlimage) {
$postdata['image'] = $dlimage->uri;
}

if (!empty($introContent)) {
$postdata['intro'] = $introContent;
}

$postdata['content'] = $content;

$post->bind($postdata, array());

try {

$saveOptions = array(
'applyDateOffset' => false,
'validateData' => false,
'normalizeData' => false,
'useAuthorAsRevisionOwner' => true
);

$post->save($saveOptions);
}
catch (Exception $exception) {

echo "There was an exception saving the post: " . $exception->getMessage() . "<br /><br />";

return array();
}

return $postdata;
}
·
Thursday, 22 October 2020 12:11
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey there,

Due to our support policy, we cannot assist you with the external script again. However, I can suggest you to check the #__easyblog_post table and make sure the post published column is 1.
·
Thursday, 22 October 2020 13:16
·
0 Likes
·
0 Votes
·
0 Comments
·
As you can see, I set it, as per your instructions:


if ($postType === 'post') {
$postdata['published'] = EASYBLOG_POST_PUBLISHED;
}


I realize you won't debug others' code for them, but this is code YOU supplied for the task.
·
Thursday, 22 October 2020 13:22
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Christopher,

What I mean by my suggestion is you have to check your existing post in the post table(#__easyblog_post) at the database and see if the published column shows 1.

If the `published` column value is 1 from the post table, then you have to also ensure that the revision content data `published` value is stored as 1 in the revision table(#__easyblog_revisions).

Also, we do not guarantee customization codes provided by us will work and you are free to use your own code if ours do not work.
·
Thursday, 22 October 2020 15:35
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post