0

我认为这更像是一个与 SQL 相关的问题,而不是一个与 WP 相关的问题:::

$result = $wpdb->get_results( " SELECT *
from wp_ngg_gallery, wp_ngg_pictures
where wp_ngg_pictures.galleryid = wp_ngg_gallery.gid
and wp_ngg_gallery.gid = 10
order by wp_ngg_pictures.imagedate 
DESC " );

如果我只从 Gallery ID = 10 获取单个画廊 id 的数据(例如,示例中的 10),上面的查询可以正常工作 ::: 我想从多个画廊 ID 中检索数据我怎么能做到这一点(例如 10,8,4 ) :::

4

1 回答 1

1

use IN

wp_ngg_gallery.gid IN (10,8,4 )

full query using ANSI SQL-92 syntax

SELECT  *
FROM    wp_ngg_gallery
        INNER JOIN wp_ngg_pictures
            ON wp_ngg_pictures.galleryid = wp_ngg_gallery.gid
WHERE   wp_ngg_gallery.gid IN (10,8,4)
ORDER BY wp_ngg_pictures.imagedate DESC
于 2012-11-22T15:36:53.063 回答