10 December 2012

Search for multiple labels on Blogger

Labels for posts and displaying pages containing only articles with a specific label are pretty basic features for any blogging platform. But what if you want to search for several labels and retrieve articles that contain all those labels or any label? Is that even possible? I asked myself this at some point and a comment from yesterday prompted me to finally find the answer.

One of the solutions I discovered on the help forums uses search with a query in this format: <blog-URL>/search/?q=label:LABEL1+label:LABEL2. This returns posts with both labels. I tested it myself and it works, but it’s hard to manually build the URL and the search is case sensitive, meaning that it will return no results it you don’t input the label name exactly as created in Blogger.

While playing around on the blog I discovered an easier way to do this: modify the normal label URL in Blogger by adding a + sign followed by the name of the second label: <blog-URL>search/label/LABEL1+LABEL2. It’s easier to remember and to type, but it’s also case sensitive. It actually works with more than two labels – I only tested it with three, so I’m not sure if there is a limit to the number of labels you can add in the URL. I don’t use any labels with multiple words so I couldn’t test this case, but it’s safe to assume you need to escape spaces by replacing them with %20 just like Blogger does with the regular label pages. Blogger search multiple labels

But what about the other case, when you want to find posts with any of those labels – the OR operator instead of AND? Unfortunately the second option doesn’t seem to support OR, but the first one does: just replace the + in the search query with a vertical bar like this: <blog-URL>/search/?q=label:LABEL1|label:LABEL2. It’s fun to see this in action especially with labels that have very little to do with one another.

46 comments:

  1. oh just did Thanks man you are the best !!

    ReplyDelete
  2. Works fine without "%20" to designate a space in a label with multiple words.

    ReplyDelete
  3. yes it is awesome. its 100%working.

    ReplyDelete
  4. I had to search so many authors to learn blogger template and its complexities. But now my journey has ended as I have reached an excellent author to learn anything in Blogger. I will be commenting here of and on and seeking guidance to move forward.

    ReplyDelete
  5. Could you tell me how this will work in the case of a space in your label eg: 'Lumia 920'

    I tried Lumia%20920 but that doesnt work for me

    ReplyDelete
  6. this works well, but I also wish to add something to the page via a condition. I cannot get the condition to work. Do you know how? This is what I tried:

    ReplyDelete
    Replies
    1. I think the condition got stripped from the comment, but I found your question on StackOverflow. I'm not sure if Blogger supports on OR operator, so you should probably try to nest the conditions, something like:

      if cond='data:blog.searchLabel == Graphics' [code]
      else if cond='data:blog.searchLabel == Identity' [same code]
      else if cond='data:blog.searchLabel == Brand' [same code again]
      else [the other option]

      Not very efficient, but unfortunately I don't see another solution...

      Delete
  7. Is there any way in searching inside a specific label. So i have a label named label 1, i need to search articles only inside the label 1 and no other articles from any other labels should come.

    ReplyDelete
  8. Thanks. Works fine on my blog.

    ReplyDelete
  9. It Doesn't work with max-results=..... !!

    ReplyDelete
  10. Thank you! If works fine :)
    And you can use this method to divide your posts in categories. I´ve created a new link-tipe page whose url link is a search with two labels.
    Now, in my pages widget I have my blog posts divided properly :)

    In:
    http://inforusty.blogspot.com.es/

    One of the pages is:
    http://inforusty.blogspot.com.es/search/?q=label:me.sobra||label:me.falta

    So thank you again :)

    ReplyDelete
    Replies
    1. How did you get it working on blogger? I tried on mine, but it doesn't work. :(

      Delete
    2. thank you it's fine

      Delete
  11. The best and easiest way to search through labels is to add a menu bar on your home page. Just put the categories in the drop down menu and add the links through your labels. This will make refine and easy to track your blog posts under each label. Just check here And you will see how it works for me

    ReplyDelete
  12. Thanks for tutorial. How t to display the results of the 10 post?

    ReplyDelete
  13. thanks for this tutorial..but how can we use it with drop down search bar.?

    ReplyDelete
    Replies
    1. I'm not sure what the drop down search bar is... a search plugin for Blogger perhaps?

      Delete
  14. A user is filtering search labels from drop down menus...
    Or a list box..

    ReplyDelete
  15. Hi!

    I want to do a searcher that search in both post and labels. anyway to do it??

    Thx

    ReplyDelete
    Replies
    1. Hi,

      I haven't done any extensive tests, but it seems to me that the regular Blogger search (from the toolbar on top) does precisely that.

      Delete
  16. wwoooww... that's work for me. thanks very much. so it's the parameter...;

    {your blogspot address}/search/?q=label:LABEL1+label:LABEL2 >>> show ONLY label 1 "with" label 2

    {your blogspot address}/search/?q=label:LABEL1|label:LABEL2 >>> show ALL thread have Label 1 "and or" label 2

    :-)

    ReplyDelete
    Replies
    1. I'm forgot... LABEL must be indexed.. or created a week ago, if not CAN'T WORK.

      Delete
  17. Hello! Tried in my website: http://www.infogeekcorp.com/search/label/Cr%C3%ADticas+Cinema, but it's not showing all the results :(

    ReplyDelete
  18. Tried it, it works for mine. Great help there!

    ReplyDelete
  19. Nice Tip. It's useful for me. Thanks!

    ReplyDelete
  20. For labels with spaces in OR (|) searches, use quotes to surround the label value! For example: http://frenchdipreviews.blogspot.com/search/?q=label:%224%20of%205%22|label:%223%20of%205%22 (the %22 character is a double quote)

    ReplyDelete
    Replies
    1. http://www.cintaummahmarketing.com/search/?q=label:%22Ubat%20Herba%20Tradisional%22|label:Artikel

      Thanks.
      it worked for me

      Delete
  21. Thank you, I will try it.
    Hope Work on my Site

    ReplyDelete
  22. Thanks for information, :)

    ReplyDelete
  23. Thanks a lot
    You solved my problem

    ReplyDelete
  24. This article is very informative and easy to understand. Thank you for sharing!


    ReplyDelete
  25. Thanks, I could remove a label using negative sign -

    My tests:



    /search/?q=label:Wave show all Waves


    /search/?q=label:Wave%20-label:Social show all Waves except who has Social too


    /search/?q=label:Wave|label:Social show all Waves and all Socials but it does not show who has both


    /search/?q=label:Wave+label:Social show only Waves that has Socials too

    ReplyDelete