Skip to main content
Glama

get_page_id_by_slug

Retrieve the WordPress page ID using its slug for targeted Elementor data management. Input the slug to identify the specific page within your WordPress site.

Instructions

Retrieves the ID of a specific WordPress page by its slug.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
slugYesThe slug (URL-friendly name) of the page to find.

Implementation Reference

  • The handler function for the MCP tool 'get_page_id_by_slug'. It takes the input slug, calls the getPageIdBySlug helper, and returns the page ID formatted as MCP text content.
    async (input) => { // Handler const pageId = await getPageIdBySlug(input.slug); return { content: [ { type: "text", text: `${pageId}`, }, ], }; }
  • Zod schema defining the input parameters for the tool: a required 'slug' string.
    { // Input Schema slug: z .string() .describe("The slug (URL-friendly name) of the page to find."), },
  • src/index.js:258-279 (registration)
    Registration of the 'get_page_id_by_slug' tool using server.tool(), including name, description, schema, and inline handler.
    server.tool( "get_page_id_by_slug", "Retrieves the ID of a specific WordPress page by its slug.", { // Input Schema slug: z .string() .describe("The slug (URL-friendly name) of the page to find."), }, async (input) => { // Handler const pageId = await getPageIdBySlug(input.slug); return { content: [ { type: "text", text: `${pageId}`, }, ], }; } );
  • Supporting helper function that queries the WordPress REST API for pages matching the slug, returns the first ID found, or throws if none.
    async function getPageIdBySlug(slug) { const client = getApiClient(); let pageId = null; try { const response = await client.get(`/wp-json/wp/v2/pages`, { params: { slug: slug, _fields: 'id', // Only need the ID } }); if (response.data && response.data.length > 0) { pageId = response.data[0].id; return pageId; // Return the ID directly } else { // Throw an error if not found, to be caught by the caller throw new Error(`Page with slug '${slug}' not found.`); } } catch (error) { // Re-throw the error for the caller to handle throw error; // Propagate the error (could be Axios error or the 'not found' error) } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aguaitech/Elementor-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server