admin管理员组

文章数量:1424600

I have a problem with the query search, which means I would only look for posts with post_status = published. The problem is that after adding my conditions, wordpress writes an "OR wp_terms.name LIKE% s% that cancels all my previous conditions. How can I remove this instruction or change the OR in AND.

I have already tried various solutions including posts_where but the condition "wp_terms.name LIKE% s% always remains.

I added this condition to the function.php file of my wordpress template to filter the search.

function.php

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');

This is the generate query:

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

This is the part that I think gives problems:

AND wp_posts.post_type = 'lp_course' AND ((wp_posts.post_status = 'publish'))OR wp_terms.name LIKE '%cantieri%'

I would like to remove the final condition or change it with AND.

Can someone help me?

本文标签: phpWordpress search queryhow to modify the sql