wp_search_site
Search across posts, pages, and media on a WordPress site to find specific content with comprehensive results and metadata.
Instructions
Performs a site-wide search for content across posts, pages, and media with comprehensive results and metadata.
Usage Examples:
• Search everything: wp_search_site --term="WordPress"
• Search posts only: wp_search_site --term="tutorial" --type="posts"
• Search pages: wp_search_site --term="about" --type="pages"
• Search media: wp_search_site --term="logo" --type="media"
• Find specific content: wp_search_site --term="contact form"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured. | |
| term | Yes | The search term to look for. | |
| type | No | The type of content to search. |
Implementation Reference
- src/tools/site.ts:203-217 (handler)The handler function that implements the core logic of wp_search_site. It performs the search using the WordPressClient's search method and formats the results as a markdown list.public async handleSearchSite(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { try { const { term, type } = params as { term: string; type?: "posts" | "pages" | "media" }; const results = await client.search(term, type ? [type] : undefined); if (results.length === 0) { return `No results found for "${term}".`; } const content = `Found ${results.length} results for "${term}":\n\n` + results.map((r) => `- [${r.type}] **${r.title}**\n Link: ${r.url}`).join("\n"); return content; } catch (_error) { throw new Error(`Failed to perform search: ${getErrorMessage(_error)}`); } }
- src/tools/site.ts:56-81 (registration)The tool definition object within SiteTools.getTools() method, which registers the wp_search_site tool including its name, description, input parameters schema, and reference to the handler function.{ name: "wp_search_site", description: "Performs a site-wide search for content across posts, pages, and media with comprehensive results and metadata.\n\n" + "**Usage Examples:**\n" + '• Search everything: `wp_search_site --term="WordPress"`\n' + '• Search posts only: `wp_search_site --term="tutorial" --type="posts"`\n' + '• Search pages: `wp_search_site --term="about" --type="pages"`\n' + '• Search media: `wp_search_site --term="logo" --type="media"`\n' + '• Find specific content: `wp_search_site --term="contact form"`', parameters: [ { name: "term", type: "string", required: true, description: "The search term to look for.", }, { name: "type", type: "string", description: "The type of content to search.", enum: ["posts", "pages", "media"], }, ], handler: this.handleSearchSite.bind(this), },
- src/tools/site.ts:66-79 (schema)The input parameters schema defining the 'term' (required string) and optional 'type' (enum: posts, pages, media) for the wp_search_site tool.parameters: [ { name: "term", type: "string", required: true, description: "The search term to look for.", }, { name: "type", type: "string", description: "The type of content to search.", enum: ["posts", "pages", "media"], }, ],