WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type labels in search (4 posts)

  1. Sam Scholfield
    Member
    Posted 1 year ago #

    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

  2. James Laws
    The WP Ninjas
    Posted 1 year ago #

    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.

  3. Sam Scholfield
    Member
    Posted 1 year ago #

    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.

  4. James Laws
    The WP Ninjas
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic