Skip to content

Extra-Chill/extrachill-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExtraChill Search

Network-activated WordPress plugin providing universal multisite search functionality for the Extra Chill Platform. Searches across all sites in a WordPress multisite network and displays unified results.

Features

  • Universal Multisite Search - Search all network sites or specific sites with single function call
  • Dynamic Site Discovery - Uses get_sites() to enumerate network sites with automatic WordPress blog-id-cache for performance
  • Flexible Post Type Support - Searches all public post types (posts, pages, custom post types, bbPress topics/replies)
  • Advanced Filtering - Full WP_Query parameter support including meta queries
  • Relevance Scoring - Weighted algorithm prioritizing exact matches, phrase matches, and word-level matching
  • Contextual Excerpts - Generates search-term-centered excerpts with highlighted matches
  • Cross-Site Pagination - Results sorted chronologically across all sites with 404 fix for paginated queries
  • Pagination 404 Fix - Automatically resolves WordPress 404 errors on paginated search across network sites
  • Site Badges - Visual indicators showing which site each result originates from

Requirements

  • WordPress: 5.0+
  • PHP: 7.4+
  • Multisite: WordPress multisite installation required
  • Theme: ExtraChill theme (for template integration)

Build + deployment

Build the production ZIP with ./build.sh (symlinked to /.github/build.sh).

Deployments and remote operations run through Homeboy (homeboy/ in this repo).

The build artifact is build/extrachill-search.zip.

Usage

Search All Sites

// Basic search
$results = extrachill_multisite_search( 'search term' );

// Search returns array of post objects with site metadata
foreach ( $results as $result ) {
    echo $result['post_title'];      // Post title
    echo $result['site_name'];       // Site name
    echo $result['permalink'];       // Full URL to post
}

Search Specific Sites

$results = extrachill_multisite_search(
    'search term',
    array( 'community.extrachill.com', 'extrachill.com' )
);

Advanced Search with Filters

$results = extrachill_multisite_search(
    'search term',
    array(),  // Empty array = all sites
    array(
        'limit'       => 20,
        'offset'      => 0,
        'post_status' => array( 'publish' ),
        'orderby'     => 'date',
        'order'       => 'DESC',
        'meta_query'  => array(
            array(
                'key'     => '_bbp_forum_id',
                'value'   => '1494',
                'compare' => '!=',
            ),
        ),
    )
);

Template Functions

// Get paginated search results with total count
list( $results, $total ) = extrachill_get_search_results( $_GET['s'], $page, $per_page );

// Generate pagination UI
extrachill_search_pagination( $total, $per_page, $page, $_GET['s'] );

// Get contextual excerpt with search term highlighted
$excerpt = ec_get_contextual_excerpt_multisite( $post_content, $search_term, 300 );

Architecture

Network Sites Covered

The plugin searches across all sites in your WordPress multisite network. In the Extra Chill Platform, this includes all 10 active sites:

  1. extrachill.com - Main site (Blog ID 1)
  2. community.extrachill.com - Forums (Blog ID 2)
  3. shop.extrachill.com - E-commerce (Blog ID 3)
  4. artist.extrachill.com - Artist platform (Blog ID 4)
  5. events.extrachill.com - Events calendar (Blog ID 7)
  6. stream.extrachill.com - Live streaming (Blog ID 8)
  7. newsletter.extrachill.com - Newsletter (Blog ID 9)
  8. docs.extrachill.com - Documentation (Blog ID 10)
  9. wire.extrachill.com - News wire (Blog ID 11)
  10. horoscope.extrachill.com - Horoscopes (Blog ID 12)

Search Result Structure

array(
    'ID'           => 123,                    // Post ID
    'post_title'   => 'Post Title',           // Post title
    'post_content' => 'Full content...',      // Full content
    'post_excerpt' => 'Excerpt...',           // Excerpt
    'post_date'    => '2025-10-07 12:00:00',  // Publication date
    'post_type'    => 'post',                 // Post type
    'post_name'    => 'post-slug',            // Post slug
    'post_author'  => 1,                      // Author ID
    'site_id'      => 1,                      // Blog ID
    'site_name'    => 'Extra Chill',          // Site name
    'site_url'     => 'extrachill.com',       // Site URL
    'permalink'    => 'https://...',          // Full post URL
    'taxonomies'   => array(                  // Taxonomy terms
        'category' => array( 'term_name' => term_id ),
    ),
)

Performance Optimizations

  • Static Caching - Network sites cached in memory
  • WordPress Blog-ID-Cache - Automatic blog ID caching for optimal performance
  • Efficient Blog Switching - Minimal context switching with proper error handling
  • Relevance Scoring - Weighted algorithm sorts results by match quality before pagination
  • Cross-Site Date Sorting - Results sorted chronologically across all sites

Pagination Architecture

WordPress native search only checks the current site for results. When paginating multisite search results, if the current site has no matching posts on a given page, WordPress returns 404 even though other network sites may have results.

The plugin intercepts these 404 errors via the template_redirect hook, queries all network sites to verify results exist, and overrides the 404 status when multisite results are found. This ensures pagination works correctly across all network sites.

Theme Integration

Required Theme Functions

The plugin expects your theme to provide:

  • extrachill_breadcrumbs() - Breadcrumb navigation
  • extrachill_no_results() - No results message
  • extrachill_display_taxonomy_badges() - Taxonomy badge display
  • inc/archives/post-card.php - Post card template

Action Hooks Used

  • extrachill_before_body_content - Before main content area
  • extrachill_after_body_content - After main content area
  • extrachill_search_header - Search results header area
  • extrachill_archive_below_description - Below archive description
  • extrachill_archive_above_posts - Above posts loop

Template Override Filter

The plugin uses the ExtraChill theme's template routing filter:

add_filter( 'extrachill_template_search', array( $this, 'override_search_template' ), 10 );

This integrates with the theme's universal template routing system located in inc/core/template-router.php.

File Structure

extrachill-search/
├── extrachill-search.php           # Main plugin file
├── inc/
│   ├── core/
│   │   ├── search-functions.php    # Core multisite search functionality
│   │   └── taxonomy-functions.php  # Taxonomy helpers
│   └── templates/
│       ├── template-functions.php  # Template helper functions
│       └── site-badge.php          # Site badge display component
├── templates/
│   └── search.php                  # Search results template
├── build.sh                        # Production build script
├── .buildignore                    # Build exclusions
├── CLAUDE.md                       # Developer documentation
└── README.md                       # This file

Development

Build Production Package

# Create production ZIP file
./build.sh

# Output: Only /build/extrachill-search.zip file

Development Commands

# Check PHP syntax
php -l extrachill-search.php

# Test search function (requires WordPress environment)
wp eval 'print_r(extrachill_multisite_search("test"));'

Support

Author

Chris Huber

License

GPL v2 or later

About

WordPress multisite search functionality for the Extra Chill network.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages