WordPress.org

Support

Support » Themes and Templates » Custom Post Type labels in search

Custom Post Type labels in search

  • Hi All,

    I was wondering if it’s possible to display the custom post type label (or name) in the search results.

    E.g. if you have a custom_post_type with the label (or name) Events and I type “Events” into the search box, I would expect to see the title “Events” which would link to the archive page of the post type.

    I have done some searching around and haven’t had much luck with this.

    Any help would be greatly appreciated.
    Sam

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sorry but there isn’t any way to have archive pages show up in search results as search is simply a query in the posts table. The best you could hope to do is write your own condition, perhaps at the top of search.php of your theme, to show links to archive pages based on the search query.

    I thought that would be the case. I was hoping there might be a filter or hook I could link into.

    So your thinking something like:
    if event is within the search term,
    then add the event link to the results.

    The only problem with that is that it would always be at the top of the results, but I think I could live with that…

    I know that the plugin Relevanssi can search for taxonomy terms (with the premium version) but it doesn’t have anything for custom post types.

    Thanks for your help James.

    Relevanssi searches Custom Post Types even in the free version but still wouldn’t add whole archive pages to the results, just the individual posts from the post type.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Type labels in search’ is closed to new replies.
Skip to toolbar