一次查询2个wordpress数据库表

一次查询2个wordpress数据库表,wordpress,Wordpress,我正在运行以下查询: $query = "SELECT post_title, ID, post_date_gmt, post_author FROM wp_posts WHERE post_type='course-manager' AND post_status='publish' AND SUBSTRING(post_date_gmt,1,4) = '$this->yearGet' AND

我正在运行以下查询:

$query = "SELECT post_title, ID, post_date_gmt, post_author
        FROM wp_posts 
            WHERE post_type='course-manager' 
        AND post_status='publish' 
        AND SUBSTRING(post_date_gmt,1,4) = '$this->yearGet'
        AND SUBSTRING(post_date_gmt,6,2) = '$this->monthGet'
        AND post_author = '$userid'
        ORDER BY post_title"; 
        $query_result = mysql_query ($query);
        while ($info = mysql_fetch_array($query_result))
        {
目前,这只是查询wordpress posts表。我还想从wordpress PosteTa表中查询数据,例如,我在PosteTa表中添加了“和课程日期”:

 $query = "SELECT post_title, ID, post_date_gmt, post_author
        FROM wp_posts 
            WHERE post_type='course-manager' 
        AND post_status='publish' 
        AND SUBSTRING(post_date_gmt,1,4) = '$this->yearGet'
        AND SUBSTRING(post_date_gmt,6,2) = '$this->monthGet'
        AND post_author = '$userid'
            AND course_date = '$this->yearGet'
        ORDER BY post_title"; 
        $query_result = mysql_query ($query);
        while ($info = mysql_fetch_array($query_result))
        {

如果您需要查询源于多个表的组合数据集,则需要进行连接。基本上,您需要在两个表之间建立连接,在post和POSTETA情况下,该连接将是post id。因此,查询应如下所示:

SELECT a.something, b.anotherthing
FROM wp_posts AS a JOIN wp_postmeta AS b
ON a.ID = b.post_id
//followed by all of your where clause...

感谢您的回复,当我将其添加到中时,我得到以下错误:警告:mysql_fetch_array()希望参数1是resource,布尔值在第100行的/home/sjm/public_html/education/wp content/themes/1024px/inc/diaryClass.php中给出