wordpress搜索自定义帖子类型在帖子元字段和另一个自定义帖子类型

时间:2014-03-25 12:42:28

标签: php wordpress query-optimization

需要帮助搜索具有3个postmeta字段的wordpress自定义帖子类型'product'的替代品

postmeta Keys
key 1 = 'Short Description'
key 2 = 'Long Description'
key 3 = 'Cat '

“key 3”的meta_value是custom_post_type'CroductCategories'的序列化ID

我需要搜索((key1或key2)和键3) 即,用户在所选类别中搜索产品名称,以便进行简短描述或长描述以及特定类别

以下查询使用起来并不是很快,并且不能容忍超过45个以上

SELECT DISTINCT posts.ID, posts.post_content, 
                        posts.post_title, meta.meta_key, meta.meta_value, 
                        meta.post_id 
                        FROM wsh_posts posts
                        LEFT JOIN wsh_postmeta meta
                        ON posts.ID = meta.post_id
                        RIGHT JOIN wsh_postmeta cat 
                        ON cat.post_id = posts.ID 
                        WHERE posts.post_type = "product" 
                        AND posts.post_status = "publish"
                AND
                (
                     (
                            cat.meta_value REGEXP("(.*)117124(.*)|(.*)117136(.*)|(.*)117135(.*)|(.*)117091(.*)|(.*)117083(.*)|(.*)117080(.*)|(.*)117113(.*)|(.*)111516(.*)|(.*)111180(.*)|(.*)108030(.*)|(.*)108031(.*)|(.*)116316(.*)|(.*)114867(.*)|(.*)114251(.*)|(.*)113220(.*)|(.*)113201(.*)|(.*)108109(.*)|(.*)108057(.*)|(.*)114925(.*)|(.*)114805(.*)|(.*)114665(.*)|(.*)114654(.*)|(.*)114167(.*)|(.*)113981(.*)|(.*)113929(.*)|(.*)113845(.*)|(.*)114881(.*)|(.*)113897(.*)|(.*)113846(.*)|(.*)113465(.*)|(.*)113255(.*)|(.*)112907(.*)|(.*)112861(.*)|(.*)117100(.*)|(.*)117098(.*)|(.*)117096(.*)|(.*)117093(.*)|(.*)116261(.*)|(.*)114383(.*)|(.*)112875(.*)|(.*)112862(.*)|(.*)112603(.*)|(.*)112276(.*)|(.*)112057(.*)|(.*)111880(.*)|(.*)111776(.*)|(.*)111658(.*)|(.*)117105(.*)|(.*)116426(.*)|(.*)116387(.*)|(.*)116305(.*)|(.*)111771(.*)|(.*)111746(.*)|(.*)111695(.*)|(.*)111674(.*)|(.*)111663(.*)|(.*)111659(.*)|(.*)111655(.*)|(.*)111493(.*)|(.*)111467(.*)|(.*)111442(.*)|(.*)111367(.*)|(.*)111259(.*)|(.*)111231(.*)|(.*)111210(.*)|(.*)111204(.*)|(.*)111205(.*)|(.*)110978(.*)|(.*)111096(.*)|(.*)110929(.*)|(.*)110680(.*)|(.*)110475(.*)|(.*)110422(.*)|(.*)117078(.*)|(.*)110423(.*)|(.*)110245(.*)|(.*)110209(.*)|(.*)110186(.*)|(.*)113776(.*)|(.*)113662(.*)|(.*)112226(.*)|(.*)112193(.*)|(.*)112139(.*)|(.*)112109(.*)|(.*)110687(.*)|(.*)110673(.*)|(.*)110649(.*)|(.*)110626(.*)|(.*)110611(.*)|(.*)110345(.*)|(.*)110333(.*)|(.*)110187(.*)|(.*)109741(.*)|(.*)109603(.*)|(.*)109052(.*)|(.*)108665(.*)|(.*)108644(.*)|(.*)108442(.*)|(.*)108415(.*)|(.*)108271(.*)|(.*)115656(.*)|(.*)115647(.*)|(.*)108217(.*)|(.*)108163(.*)|(.*)108159(.*)|(.*)108006(.*)|(.*)107873(.*)|(.*)107784(.*)|(.*)110889(.*)|(.*)110852(.*)|(.*)108150(.*)|(.*)107888(.*)|(.*)107789(.*)|(.*)107785(.*)|(.*)107680(.*)|(.*)115191(.*)|(.*)111874(.*)|(.*)107767(.*)|(.*)107706(.*)|(.*)107698(.*)|(.*)107659(.*)|(.*)107645(.*)|(.*)112664(.*)|(.*)112176(.*)|(.*)109335(.*)|(.*)109263(.*)|(.*)109111(.*)|(.*)109065(.*)|(.*)107646(.*)|(.*)107644(.*)") 
                            AND cat.meta_key = "cat"
                    )
                    AND 
                    (
                        (
                            meta.meta_key = "shortDescription" 
                            OR meta.meta_key = "longDescription"
                        )
                        AND (
                            meta.meta_value LIKE "%beanies%" 
                            OR posts.post_title LIKE "%beanies%" 
                            OR posts.post_content LIKE "%beanies%"
                        )
                    )
                ) GROUP BY posts.ID
                   LIMIT 0, 35

0 个答案:

没有答案