2 formatting and readability
source | link

Exclude html content from search Strip HTML Tags From Search Results

<?php
function super_search_exclude_activate() {
    $striptags = "CREATE FUNCTION fnStripTags( Dirty longtext )
        RETURNS longtext
        DETERMINISTIC 
        BEGIN
          DECLARE iStart, iEnd, iLength int;
            WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
              BEGIN
                SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
                SET iLength = ( iEnd - iStart) + 1;
                IF iLength > 0 THEN
                  BEGIN
                    SET Dirty = Insert( Dirty, iStart, iLength, '');
                  END;
                END IF;
              END;
            END WHILE;
            RETURN Dirty;
        END;";
    global $wpdb;
    $wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
    $wpdb->query($striptags);
}
register_activation_hook(__FILE__, 'super_search_exclude_activate');

function super_search_exclude_deactivate() {
    global $wpdb;
    $wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
}
register_deactivation_hook(__FILE__, 'super_search_exclude_deactivate');

function super_search_exclude_posts_search($search) {
    if (is_search()) {
        global $wpdb;
        if (stripos($search, 'post_content LIKE')) {
            $search = str_replace("{$wpdb->posts}.post_content LIKE", "fnStripTags({$wpdb->posts}.post_content) LIKE", $search);
        }
    }
    return $search;
}
add_filter('posts_search', 'super_search_exclude_posts_search');

The thing is that I don't have any error message but the search engine doesn't return anya result anymore, unlesunless I deactivate the plugin and then I'm back to square one.

Exclude html content from search

function super_search_exclude_activate() {
$striptags = "CREATE FUNCTION fnStripTags( Dirty longtext )
RETURNS longtext
DETERMINISTIC 
BEGIN
  DECLARE iStart, iEnd, iLength int;
    WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
      BEGIN
        SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
        SET iLength = ( iEnd - iStart) + 1;
        IF iLength > 0 THEN
          BEGIN
            SET Dirty = Insert( Dirty, iStart, iLength, '');
          END;
        END IF;
      END;
    END WHILE;
    RETURN Dirty;
END;";
global $wpdb;
$wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
$wpdb->query($striptags);
}
register_activation_hook(__FILE__, 'super_search_exclude_activate');

function super_search_exclude_deactivate() {
global $wpdb;
$wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
}
register_deactivation_hook(__FILE__, 'super_search_exclude_deactivate');

function super_search_exclude_posts_search($search) {
if(is_search()) {
    global $wpdb;
    if(stripos($search, 'post_content LIKE')) {
        $search = str_replace("{$wpdb->posts}.post_content LIKE", "fnStripTags({$wpdb->posts}.post_content) LIKE", $search);
    }
}
return $search;
}
add_filter('posts_search', 'super_search_exclude_posts_search');

The thing is that I don't have any error message but the search engine doesn't return any result anymore, unles I deactivate the plugin and then I'm back to square one.

Strip HTML Tags From Search Results

<?php
function super_search_exclude_activate() {
    $striptags = "CREATE FUNCTION fnStripTags( Dirty longtext )
        RETURNS longtext
        DETERMINISTIC 
        BEGIN
          DECLARE iStart, iEnd, iLength int;
            WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
              BEGIN
                SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
                SET iLength = ( iEnd - iStart) + 1;
                IF iLength > 0 THEN
                  BEGIN
                    SET Dirty = Insert( Dirty, iStart, iLength, '');
                  END;
                END IF;
              END;
            END WHILE;
            RETURN Dirty;
        END;";
    global $wpdb;
    $wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
    $wpdb->query($striptags);
}
register_activation_hook(__FILE__, 'super_search_exclude_activate');

function super_search_exclude_deactivate() {
    global $wpdb;
    $wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
}
register_deactivation_hook(__FILE__, 'super_search_exclude_deactivate');

function super_search_exclude_posts_search($search) {
    if (is_search()) {
        global $wpdb;
        if (stripos($search, 'post_content LIKE')) {
            $search = str_replace("{$wpdb->posts}.post_content LIKE", "fnStripTags({$wpdb->posts}.post_content) LIKE", $search);
        }
    }
    return $search;
}
add_filter('posts_search', 'super_search_exclude_posts_search');

I don't have any error message but the search engine doesn't return a result unless I deactivate the plugin and then I'm back to square one.

1
source | link

Exclude html content from search

When I make a search, if there is an image title within a img tag, it's displayed in a very ugly fashion among the search results (the whole tag is displayed and the picture too). I found this script which is supposed to solve the problem and this is the only thing I found about the subject over the internet.

function super_search_exclude_activate() {
$striptags = "CREATE FUNCTION fnStripTags( Dirty longtext )
RETURNS longtext
DETERMINISTIC 
BEGIN
  DECLARE iStart, iEnd, iLength int;
    WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
      BEGIN
        SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
        SET iLength = ( iEnd - iStart) + 1;
        IF iLength > 0 THEN
          BEGIN
            SET Dirty = Insert( Dirty, iStart, iLength, '');
          END;
        END IF;
      END;
    END WHILE;
    RETURN Dirty;
END;";
global $wpdb;
$wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
$wpdb->query($striptags);
}
register_activation_hook(__FILE__, 'super_search_exclude_activate');

function super_search_exclude_deactivate() {
global $wpdb;
$wpdb->query("DROP FUNCTION IF EXISTS fnStripTags");
}
register_deactivation_hook(__FILE__, 'super_search_exclude_deactivate');

function super_search_exclude_posts_search($search) {
if(is_search()) {
    global $wpdb;
    if(stripos($search, 'post_content LIKE')) {
        $search = str_replace("{$wpdb->posts}.post_content LIKE", "fnStripTags({$wpdb->posts}.post_content) LIKE", $search);
    }
}
return $search;
}
add_filter('posts_search', 'super_search_exclude_posts_search');

The thing is that I don't have any error message but the search engine doesn't return any result anymore, unles I deactivate the plugin and then I'm back to square one.

What would be the issue?

PS: I created a plugin from this script and activated it in the right admin section.