我的一些帖子的类名称为“已禁用”,我必须将它们从相关帖子中删除,因为它们具有样式显示:无,因此它会插入它但不显示它。
如何过滤禁用类名的帖子并将它们添加到“posts__not_in”以避免它们?
ab -p search_test.txt -T application/json -n 10 http://host-url?userQuery=air
答案 0 :(得分:1)
我的建议是创建一个类别并将其分配给帖子。然后使用 tax_query 从 get_posts() 中过滤掉这些帖子。下面的例子是伪代码:
$related = get_posts([
'post_type' => 'post',
'numberposts' => 4,
'post__not_in' => [$post->ID],
'tax_query' => [
[
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'DISABLED_CATEGORY_SLUG',
'operator' => 'NOT IN'
],
],
]);