来自 Wordpress Taxonomy Query 的双倍


Doubles from Wordpress Taxonomy Query

我从这个wordpress查询中得到了双打:

SELECT LEFT(main.post_title , 1) AS `character`,
            main.post_title AS title,
            main.post_content AS content,
            parent_data.name AS parent_title,
            root_data.name AS root_title,
            thumbnail_data.meta_value AS thumbnail_url,
            main.ID
        FROM wp_jlwx_posts AS main
            INNER JOIN wp_jlwx_term_relationships AS parent ON main.ID = parent.object_id
            INNER JOIN wp_jlwx_term_taxonomy AS parent_taxonomy ON parent.term_taxonomy_id = parent_taxonomy.term_taxonomy_id
            INNER JOIN wp_jlwx_terms AS parent_data ON parent_taxonomy.term_id = parent_data.term_id
            INNER JOIN wp_jlwx_term_taxonomy AS root_taxonomy ON parent_taxonomy.parent = root_taxonomy.term_taxonomy_id
            INNER JOIN wp_jlwx_terms AS root_data ON root_taxonomy.term_taxonomy_id = root_data.term_id
            LEFT JOIN wp_jlwx_postmeta AS linker    ON main.ID = linker.post_id AND linker.meta_key = '_thumbnail_id'
            LEFT JOIN wp_jlwx_postmeta AS thumbnail_data    ON linker.meta_value = thumbnail_data.post_id
            WHERE main.post_type = 'business' 
                AND main.post_status = 'publish'
                $search_where_clause
            $character_have_clause
            ORDER BY root_title, parent_title, title

我跳出的第一件事是我在分类表上加入了两次。如何确保"主"表中的每一行只返回一行?

(编辑)我能够将其缩小到缩略图连接,我在其中从元表中接收额外的数据:例如 a:5:{s:5:"宽度";i:960;s:6:"高度"...

能够找到问题:

Wordpress 在将缩略图添加到元表中时存储元数据。

该位置与meta_key:一起存储,_wp_attached_file额外的数据存储在meta_key:_wp_attachment_metadata中。

因此,如果我将meta_key ="_wp_attached_file"添加到最后一个连接中,我的问题就解决了。