0

我正在尝试实现搜索,它将查看自定义分类术语。我有称为“产品”的自定义类型,以及称为“类型”的自定义分类。当我使用 wordpress 标准表单时,它工作得很好,除了它不会在自定义分类术语中搜索。

所以,我需要的是: 1. 让 WP 搜索“m_type”分类术语 2. 它应该使用术语的“名称”,而不是“slug”。

我试图包含其他查询变量,以使其至少通过“slugs”进行查看。

这段代码:

$wp_query->query['tax_query'] =  array(
        array(
            'taxonomy' => 'm_type',
            'field' => 'slug',
            'terms' => 'pen'
        )
    );

生成以下 SQL:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships 
ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON 
(wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id 
IN (163) ) AND (((wp_posts.post_title LIKE '%pen%') OR (wp_posts.post_content LIKE 
'%pen%'))) AND wp_posts.post_type IN ('product') AND (wp_posts.post_status 
= 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') AND
 (wp_postmeta.meta_key = 'max_price' ) GROUP BY wp_posts.ID 
ORDER BY wp_postmeta.meta_value+0 DESC LIMIT 0, 60

因此,基本上它添加了自定义分类法,搜索具有这种分类法 (*wp_term_relationships.term_taxonomy_id IN (163)*) 但实际上从未将分类术语与查询字符串进行比较的帖子。

也许我做错了所有这些?

4

1 回答 1

1

我正在使用此 sql 查询根据标题/分类术语/内容搜索来获取结果,其中 $search 是搜索参数,而 $_REQUEST['post_type'] 我是 p

                SELECT DISTINCT(ID) FROM 
                $wpdb->terms AS terms 
                JOIN
                $wpdb->term_taxonomy as termtaxonomy
                JOIN
                $wpdb->term_relationships AS termrelationship
                JOIN
                $wpdb->posts AS posts

                ON terms.term_id = termtaxonomy.term_id &&
                   termrelationship.term_taxonomy_id = termtaxonomy.term_taxonomy_id &&
                   termrelationship.object_id = posts.ID
                WHERE terms.name LIKE '%".$search."%' OR posts.post_title LIKE       '%".$search."%' OR posts.post_content LIKE '%".$search."%' AND posts.post_type='".$_REQUEST['post_type']
于 2013-11-22T09:55:44.427 回答