WordPress.org

Ready to get started?Download WordPress

Forums

Sort search results by category (11 posts)

  1. pro01
    Member
    Posted 4 years ago #

    Does anyone know if search results can be sorted by category, so final output looks something like:

    3 results found

    Articles
    --------
    Blah blah article

    News
    ----
    Blah blah news title

    Events
    ------
    Blah blah event

    Tried to trick it out, but without much luck so far. Don't even know if it is possible in the first place.

  2. andrea82
    Member
    Posted 4 years ago #

    Same question here... Up!!

  3. racer x
    Member
    Posted 4 years ago #

    Do you want these in one long list like regular archives only sectioned?
    The way I see it you may have one of two situations to consider.

    1. You either have a few hundred posts and at 20 or so per page, you may not really have a situation where there would be multiple categories of posts on one page.(If that makes sense.)
    2. The other situation is that you have only a few posts in each category and really only need to show 4-6 posts from each. In which case, they can be separated by category for easy viewing and allow you to title each section accordingly.

    In the first case, you might be better off just creating archive pages such as category-articles.php, category-News.php, etc. Just copy your archive template but title the file accordingly. (There are other ways to do this as well.)

    In the second case, you can have multiple loops on a page. If you are a coder these tuts may help:
    http://perishablepress.com/press/2008/09/01/multiple-loops-and-multiple-columns-with-wordpress/
    http://codex.wordpress.org/The_Loop

    For one long list as a regular Archive you can also use orderby=parent in those query_posts.

  4. andrea82
    Member
    Posted 4 years ago #

    Racer x, thanks for your reply...

    I only need to be able to show all the posts for a given keyword for category #2 but not for all the categories available at my blog.

    Is there a way to have a link like:

    http://www.myblog.com/?s=Phoenix&cat=2

    Where &cat=2 means that I'm searching for the keyword "Phoenix" only in the category with id 2?

    I'd like to hope that there is already a code to append to the search link result page as I'm not absoulutely looking for a search form (just for the link that returns the results for a given keyword for a given category).

    Sorry for the long post but I hope I've clarified my thought...

    Thanks

    Andrea

  5. Mark / t31os
    Moderator
    Posted 4 years ago #

    You can add category to the search but it does require adding a few additional rules to the rewrite array.

    The alternative is to try some of the plugins that extend the search capabilities, avoiding any need to understand how to add to the rewrite array.
    http://wordpress.org/extend/plugins/tags/search

  6. racer x
    Member
    Posted 4 years ago #

    It is possible that your theme's archive.php page has a bunch of php "conditional" statements. This means it detects if the query is an archive by category, archive by month, archive by tags, etc.

    If your theme has these conditional checks then you could simply add a tag(the keyword in this case) to the posts that have that keyword in the story.

    Then you just create a link to that tag's archive in this manner:
    yoursite.com/tag/keyword/

    Provided you have that permalink structure.

  7. andrea82
    Member
    Posted 4 years ago #

    Hope that it could have been a little easier...

    Racer, the idea of the tag appended to the post doesn't work for me as all my posts are coming from feeds and check any post to insert the tag would take me days...

    I've also take a look to the plugin section but, as I supposed, there is not a perfect one to have easily what I (and suppose a lot of editors) need.

    Andrea

  8. racer x
    Member
    Posted 4 years ago #

    Have you tried an advanced search plugin?

    Something like this claims it allows a search to be limited to a category. (I have not used this or know how good it is.)

    You'd have to go through many of the search plugins and see which is most recently updated, well received by the community, etc.

  9. andrea82
    Member
    Posted 4 years ago #

    WordPress advanced search seems not to play very well in 2.9.2 or at least there's no way to search within categories.

    I've tried some of the search plugins available but with absolutely no luck.

    I'm starting to think that it's something not available by default or by plugin.

    That's a real shame as this blog platform would be "more" perfect with it...

  10. andrea82
    Member
    Posted 4 years ago #

    Search Unleashed is the only that gets close to my goal...

  11. Mark / t31os
    Moderator
    Posted 4 years ago #

    If you want something to be modified/customised beyond standard functionality, that leaves you a few options.

    1. Find a plugin that does it (if not see 2).
    2. Find a plugin that comes close and modify it to suit (if not see 3).
    3. Search for information shared by someone who has already done the same (if not see 4).
    4. Hire a developer to write the customisations for you.

    So, if Search Unleashed comes close, what does it lack that you need, perhaps if you could be specific about what additions or modifications it needs someone may offer to help (they also may not - it's just a suggestion).

Topic Closed

This topic has been closed to new replies.

About this Topic