Coder Social home page Coder Social logo

zodiac1978 / wp-search-ignore-block-names Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 3.0 262 KB

Modifies the native search to ignore block editor comments

Home Page: https://wordpress.org/plugins/ignore-block-name-in-search/

License: GNU General Public License v2.0

PHP 100.00%
blockeditor gutenberg search wordpress wordpress-plugin

wp-search-ignore-block-names's Issues

Adding a toggle for the internal search in admin area

Looks like an excellent solution. Does this filter backend searches as well? I find that searching for blocks can be quite useful there. Might be worth adding an is_admin()...
Source: Roy Tanck (@roytanck) on Twitter

To allow searching for blocks as well, we could add a toggle to enable/disable searching for block comments.

Not working as expected

Your solution doesn't work when the search term is in both tags and content. ex: this is a paragraph the post with this content doesn't get captured when searching for "paragraph" because of the AND clause in your query

See: https://core.trac.wordpress.org/ticket/56294#comment:5

Unfortunately I did not find a simple way to achieve this with MySQL below 8.
Since MySQL 8 there is REPLACE_REGEXP which would solve this:
https://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql

See: https://core.trac.wordpress.org/ticket/56294#comment:6

I will try to get this working at least with MySQL 8+ (and with the according MariaDB version). If this works, there needs to be some MySQL version checking built in.

Search for title and excerpt is broken with this plugin

A simplified Query for a standard search is this

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
FROM wp_posts WHERE 1=1 
AND (((wp_posts.post_title LIKE '%wat%') 
OR (wp_posts.post_excerpt LIKE '%wat%') 
OR (wp_posts.post_content LIKE '%wat%')))

This plugin adds a new condition:

$where .= " AND REGEXP_REPLACE({$wpdb->posts}.post_content, '<.+?>', '') LIKE '%{$search_query}%'";

This breaks searching for title and excerpt.

We need to add the two OR statements again to fix this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.