WordPress搜索查询,如何修改sql

时间:2019-06-04 09:14:11

标签: php wordpress

查询搜索存在问题,这意味着我只会查找post_status =已发布的帖子。问题在于,添加条件后,wordpress会写一个“ OR wp_terms.name LIKE%s%来取消我以前的所有条件。如何删除此指令或更改AND中的OR。

我已经尝试过各种解决方案,包括posts_where,但条件“ wp_terms.name LIKE%s%始终保持不变。”

我将此条件添加到了wordpress模板的function.php文件中以过滤搜索。

function.php

for $theHoldingListsField in //DisplaySettingCol/theDisplaySetting/theHoldingListsFields
return (
  if ($theHoldingListsField/@AFL != "MANDATORY") then (
    <error id="DPR-CKSEM-DEP-SMF142-2">
      <args>
        <arg value="{$theHoldingListsField/ancestor::node()/@id}"/>
        <arg value="AFL = {$theHoldingListsField/@AFL}"/>
      </args>
      <location value="{functx:path-to-node-with-pos($theHoldingListsField)}"/>
    </error>
  ) else (),
  if ($theHoldingListsField/@attitudeIndicator != "MANDATORY") then (
    <error id="DPR-CKSEM-DEP-SMF142-2">
      <args>
        <arg value="{$theHoldingListsField/ancestor::node()/@id}"/>
        <arg value="attitudeIndicator = {$theHoldingListsField/@attitudeIndicator}"/>
      </args>
      <location value="{functx:path-to-node-with-pos($theHoldingListsField)}"/>
    </error>
  ) else ()
)

这是生成查询:

function nameFunction($query){
    if (!is_admin() && $query->is_main_query()) {
            if ($query->is_search()) {

                $query->set( 'post_status', 'publish');
                $query->set( 'post_type', 'lp_course');
                $query->set('s', get_search_query());
                $query->set('order', 'desc' );
            }
    }
}

add_action( 'pre_get_posts', 'nameFunction');

这是我认为会出现问题的部分

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id LEFT JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id LEFT JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id WHERE 1=1 AND (((wp_posts.post_title LIKE '{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}cantieri{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}') OR (wp_posts.post_excerpt LIKE '{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}cantieri{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}') OR (wp_posts.post_content LIKE '{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}cantieri{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}'))) AND (wp_posts.post_password = '') AND wp_posts.post_type = 'lp_course' AND ((wp_posts.post_status = 'publish'))OR wp_terms.name LIKE '%cantieri%' GROUP BY wp_posts.ID ORDER BY wp_posts.post_title LIKE '{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}cantieri{49d63a129bd514e58a4ec329ce90100d6896c431356d4f358f3b347caaecea35}' DESC, wp_posts.post_date DESC LIMIT 0, 10

我想删除最终条件或使用AND进行更改。

有人可以帮我吗?

0 个答案:

没有答案