0

I have a pre_get_posts() function that is used by my users to search posts. I've noticed that for whatever reason it seems to be searching text within a post's previous revision that is no longer in the post and return the current post.

ROUGH EXAMPLE:

Previous Revision Title = "I like to analyze"
Current Title = "I like to report"

Now if you search for "analyze" it would return the post with the Current Title which I would prefer it not to.

I've setup the query in a way I thought would remove this...but it's not:

$search_post_types_array = array('zr_td','st_kb','forum','topic','reply');
$query->set('post_type', $search_post_types_array);
$query->set('post_status', 'publish');
$query->set('post_parent', 0);

Please let me know if you need additional clarification or information.

SQL from $wp_query->request;

SELECT DISTINCT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_postmeta AS m ON (wp_posts.ID = m.post_id) WHERE 1=1 AND ( ( wp_posts.post_parent = 0 AND (((((wp_posts.post_title LIKE '%analytics%') OR (wp_posts.post_content LIKE '%analytics%'))) OR ((m.meta_value LIKE '%analytics%')) )) AND wp_posts.post_type IN ('zr_td', 'st_kb', 'forum', 'topic', 'reply') AND ((wp_posts.post_status = 'publish'))) AND post_type != 'revision') AND post_status != 'future' ORDER BY wp_posts.post_title LIKE '{a2ab97c8fd44df4b50f3dc2108b2651d7e3390dcacd7fd0413334d3fd0287ce9}analytics{a2ab97c8fd44df4b50f3dc2108b2651d7e3390dcacd7fd0413334d3fd0287ce9}' DESC, wp_posts.post_date DESC LIMIT 0, 10

5
  • 1
    Have you tried setting the post_type explicitly? Also, can you add the SQL actually being run ($wp_query->request)?
    – janh
    Dec 19, 2017 at 15:37
  • Can you show how SQL looks like?
    – kierzniak
    Dec 19, 2017 at 15:37
  • I do set the post types explictly; I have updated the original question with it
    – Ray
    Dec 19, 2017 at 15:44
  • @motivast I have added the SQL...I think that is running
    – Ray
    Dec 19, 2017 at 15:51
  • 1
    Do you see that you are searching also in meta_value of each post? Can you confirm that there is no analyze value in posts like "I like to report"?
    – kierzniak
    Dec 19, 2017 at 16:01

1 Answer 1

0

Found it thanks for the investigation tips guys!

So when it was doing the meta_value search the search term was showing up the meta_key _wp_old_slug's meta_value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.