• vijayj

    (@vijayj)


    The main page contents of my website is by using shortcode.And during searching these contents are not displayed.How can I include shortcodes in search results

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m sorry, you cannot. Shortcodes come from code and searches come from the DB. Two completely different resources. More accurately, such a search would be so computationally expensive as to be close to impossible.

    There are a few exceptions. You can search for the shortcode tag itself, but not what the shortcode outputs. In specific situations where a shortcode queries the DB for its content, it may be possible to include a search of whatever the shortcode queries as part of a larger search effort. However, it’s likely the reference found would link to another resource besides the page using the shortcode.

    Thread Starter vijayj

    (@vijayj)

    Thanks.So I am planning to create an API to call the search in remote database by adding a new function in function.php.

    How can I use the function result in search.

    The theme I am using is having search.php and searchform.php

    Moderator bcworkz

    (@bcworkz)

    You can use some action that fires in the normal search process to make an API query. You end up with two structurally disparate results. An array of post objects and whatever the API returns. What you do with that depends on how you want to present the results. Consider how pagination affects what you do, i.e. the usual WP search query only returns one page full of posts. The API request probably doesn’t.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Include shortcode results in search’ is closed to new replies.