• Resolved victoryph

    (@victoryph)


    How can I include tags on search im trying to add some codes but
    it only works when i deactivate the searchiq plugin here’s the code im using.

    function my_smart_search( $search, &$wp_query ) {
        global $wpdb;
    
        if ( empty( $search ))
            return $search;
    
        $terms = $wp_query->query_vars[ 's' ];
        $exploded = explode( ' ', $terms );
        if( $exploded === FALSE || count( $exploded ) == 0 )
            $exploded = array( 0 => $terms );
    
        $search = '';
        foreach( $exploded as $tag ) {
            $search .= " AND (
                (wp_posts.post_title LIKE '%$tag%')
                OR (wp_posts.post_content LIKE '%$tag%')
                OR EXISTS
                (
                    SELECT * FROM wp_comments
                    WHERE comment_post_ID = wp_posts.ID
                        AND comment_content LIKE '%$tag%'
                )
                OR EXISTS
                (
                    SELECT * FROM wp_terms
                    INNER JOIN wp_term_taxonomy
                        ON wp_term_taxonomy.term_id = wp_terms.term_id
                    INNER JOIN wp_term_relationships
                        ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
                    WHERE taxonomy = 'post_tag'
                        AND object_id = wp_posts.ID
                        AND wp_terms.name LIKE '%$tag%'
                )
            )";
        }
    
        return $search;
    }
    
    add_filter( 'posts_search', 'my_smart_search', 500, 2 );

    https://www.ads-software.com/plugins/searchiq/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Tag to Search’ is closed to new replies.