Skip to content

Developer Documentation

Technical reference for developers extending or contributing to WP Loupe – Admin Search.

WP Loupe Admin maintains its own search indexes, separate from the main WP Loupe plugin. This allows the admin to index all post statuses relevant to editorial workflows (publish, draft, pending, private, future), whereas the main plugin only indexes published content.

Indexes are stored at {wp_loupe_db_path}/admin/{entity_type}/ as SQLite databases. They are created automatically on the first admin page load and kept in sync incrementally.

Every indexed post type gets these core fields:

FieldSearchableFilterableSortableWeight
post_title3.0
post_content1.0
post_excerpt1.5
post_name1.0
post_status
post_date
author_name2.0

Taxonomy fields are added automatically for each show_ui taxonomy attached to the post type (e.g. taxonomy_category, taxonomy_post_tag):

FieldSearchableFilterableSortableWeight
taxonomy_{name}1.5

Weights control how much each field contributes to search relevance. A weight of 3.0 means a match in post_title ranks three times higher than a match in post_content.

Any field not matched to a WP_Post property, virtual field, or taxonomy falls back to get_post_meta().

FieldSearchableFilterableSortableWeight
display_name3.0
user_login2.0
user_email2.0
user_role
FieldSearchableFilterableSortableWeight
comment_content1.0
comment_author2.0
comment_author_email1.0
comment_date
FieldSearchableFilterableSortableWeight
plugin_name3.0
plugin_description1.0
plugin_author2.0
plugin_status

Filter the indexed fields for any entity type. Use this to add custom meta fields to the search index.

add_filter( 'wp_loupe_admin_schema', function ( array $fields, string $entity_type ): array {
if ( 'post' === $entity_type ) {
$fields['my_custom_meta'] = [
'searchable' => true,
'filterable' => false,
'sortable' => false,
'weight' => 1.0,
];
}
return $fields;
}, 10, 2 );

After changing the schema, delete the admin index folder (wp-loupe-db/admin/) to trigger a full rebuild on the next admin page load.

Search endpoint with scope parameter.

Method: GET

Parameters:

ParameterTypeRequiredDescription
sstringyesSearch query
scopestringnoSearch scope: content (default), users, plugins, comments
pageintegernoPage number (default 1)

Capability requirements per scope:

ScopeRequired Capability
contentedit_posts
userslist_users
pluginsactivate_plugins
commentsmoderate_comments

The plugin intercepts native WordPress admin search in three places:

  • Posts list table — via posts_pre_query filter in WP_Loupe_Admin_Query_Integration
  • Users list table — via pre_get_users in WP_Loupe_Admin_User_Query_Integration
  • Comments list table — via pre_get_comments in WP_Loupe_Admin_Comment_Query_Integration

Each integration includes a re-entrancy guard to prevent infinite loops.

Terminal window
# Rebuild all admin indexes
wp loupe-admin reindex
# Show index status
wp loupe-admin status
ClassResponsibility
WP_Loupe_Admin_LoaderRequest-scoped singleton bootstrap
WP_Loupe_Admin_SchemaField definitions per entity type
WP_Loupe_Admin_IndexerPost type indexing
WP_Loupe_Admin_User_IndexerUser indexing
WP_Loupe_Admin_Comment_IndexerComment indexing
WP_Loupe_Admin_Plugin_IndexerPlugin indexing (non-DB source)
WP_Loupe_Admin_Query_Integrationposts_pre_query interception
WP_Loupe_Admin_User_Query_Integrationpre_get_users interception
WP_Loupe_Admin_Comment_Query_Integrationpre_get_comments interception
WP_Loupe_Admin_RestREST API endpoint
WP_Loupe_Admin_SearchDashboard widget, admin bar, modal UI
WP_Loupe_Admin_CLIWP-CLI commands
WP_Loupe_Admin_NoticeAdmin notice for stale/missing indexes

Install dependencies:

Terminal window
composer install
npm install

Build JavaScript:

Terminal window
npm run build

Watch during development:

Terminal window
npm run dev:js

Run tests:

Terminal window
./vendor/bin/phpunit
npm run test:js

Generate translation files:

Terminal window
npm run i18n
  • src/js/ — Source JavaScript
  • lib/js/ — Built JavaScript
  • lib/css/ — Built CSS
  • includes/ — PHP classes
  • tests/ — PHPUnit and Vitest tests
  • scripts/ — Build scripts
  • languages/ — Translation files