草稿和存档帖子通过使用Anchor CMS的“相关帖子”显示

I'm using Anchor CMS.

Everything works great except posts that are labelled 'Draft' are still showing live on the site in the 'Related posts' section, yet I have no idea why as from what I can see, only published posts should show up.

This is the code I'm using to show related posts at the bottom of each article:

Functions.php

function related_posts($n) {
$posts = Post::get(Base::table('posts'), '=', 'published');
$postarr = array();
foreach($posts as $post) :
if($post->id != article_id()) {
    if($post->category == article_category_id()) {
        array_push($postarr, $post);
    }
}
endforeach;    
shuffle($postarr);
$postarr = array_slice($postarr, 0, $n);
return $postarr;
}

function article_category_id() {
if($category = Registry::prop('article', 'category')) {
$categories = Registry::get('all_categories');
return $categories[$category]->id;
}
}

Article.php

<?php foreach( related_posts(3) as $post) : ?>
<div class="similar-posts">
<div class="simi-alt">
<a href="<?= $post->slug; ?>"><?= $post->title; ?></a> 
</div>   
<p class="sim-desc"><?= $post->description; ?> <a href="<?= $post->slug; ?>">Read more..</a></p>
</div>
<?php endforeach; ?>

I don't know what is this CMS about, but the documentation on the website is not so good.

I just downloaded to investigate Post class.

class Post extends Base {
...
private static function get($row, $val) { 
...
->where(Base::table('posts.'.$row), '=', $val)

From my point of view, that means that you should send 2 parameters - one is field name and second one field value.

So I'm guessing, but you could try change this line in your code:

$posts = Post::get(Base::table('posts'), '=', 'published');

to this one:

$posts = Post::get(Base::table('posts'), 'status', 'published');

or even to:

$posts = Post::get('status', 'published');