开发者

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

开发者 https://www.devze.com 2023-02-17 17:24 出处:网络
$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 sur

$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

精彩评论

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