开发者

how would i add an array of post types in this code?

$nopages = "AND $wpdb->posts.post_type = 'post'";

In addition to the post post type, I'd like to add a couple more (i.e. 'projects' and 'videos'). I'm not much of a coder so I'm not sure where to begin. Can开发者_StackOverflow中文版 I add something like 'post_type' => array( 'post','videos','projects' ), anywhere in there?


You'll have to use IN() in your SQL query :

"AND $wpdb->posts.post_type IN ('post','videos','projects')";


And, if you have those in a PHP array, like this :

$types = array('post','videos','projects');

You can use the implode() to concatenate them into a string that can be used in an SQL query :

$types_in = implode(', ', $types);
"AND $wpdb->posts.post_type IN ($types_in)";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜