在 wordpress post

编程入门 行业动态 更新时间:2024-10-10 01:22:40
本文介绍了在 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

本文发布于:2023-11-28 20:28:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:wordpress   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!