来自Wordpress Taxonomy Query的双打

时间:2015-03-10 17:32:21

标签: php mysql sql wordpress

我从这个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

我首先想到的是,我在分类表上加入了两次。如何确保“main”表中每行只返回一行?

(编辑) 我已经能够将其缩小到缩略图连接,我从元表中收回了额外的数据:例如一:5:{S:5: “宽度”; I:960; S:6: “高度” ...

1 个答案:

答案 0 :(得分:0)

我已经找到了问题:

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

该位置与meta_key一起存储:_wp_attached_file,因为额外数据与meta_key一起存储:_wp_attachment_metadata。

因此,如果我将meta_key =“_ wp_attached_file”添加到上一次加入,我的问题就解决了。