在 wordpress post__not_in 中使用变量作为值 [英] use a variable as value in wordpress post__not_in

查看:54
本文介绍了在 wordpress post__not_in 中使用变量作为值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 $excludes 的变量,其内容如下:12,32,345,676,677,733,980 我可以像这样使用 post__not_in 吗:

I have a variable called $excludes that has the following content: 12,32,345,676,677,733,980 can I use post__not_in like this:

$the_query = new WP_Query( array( 'posts_per_page' => 10, 'post__not_in' => $excludes ) );

排除在 $excludes 中找到的帖子 ID.

To exclude the post id's found in $excludes.

推荐答案

你需要在 post__not_in 中传递一个 array() 就像 'post__not_in' =>数组(343、493、166),

you need to pass an array() in post__not_in like 'post__not_in' => array(343, 493, 166),

试试:-

$str = '12,32,345,676,677,733,980';
$arr = explode(',', $str);
$the_query = new WP_Query( array( 'posts_per_page' => 10, 'post__not_in' => $arr) );

这篇关于在 wordpress post__not_in 中使用变量作为值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆