Answers.Body: <p>If you know your <strong>q</strong> variable should be a slug, you can use the <code>.slug</code> query parameter:</p>
  
  <pre><code>{# Get the requested entry slug from the URL #}
  {% set requestedSlug = craft.app.request.getSegment(3) %}
  
  {# Fetch the entry with that slug #}
  {% set entry = craft.entries()
      .slug(requestedSlug|literal)
      .one() %}
  </code></pre>
  
  <p><a href="https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#slug" rel="nofollow noreferrer">More on how to use this in the Craft 3 docs</a>.</p>
  
  <p>I have personally had some unexpected results using Craft's built-in search. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-22T22:41:59.620Z
Answers.Text: Thanks, Alex . I ended up taking a different approach using relatedTo. Appreciate your response!
Answers.UserDisplayName: Roi Agneta
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-16T20:33:38.027Z
Answers.LastActivityDate: 2018-09-16T20:33:38.027Z
Answers.UserDisplayName: Alex Roper
Body: <p>I created Search that uses entry slug, but it fails if the slug has more than one dash "-" in it. Has anyone come across this and/or have any ideas for getting around it?</p>
  
  <p>I need to use the slug because they are unique within a section. </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-14T23:39:48.030Z
Comments.Text: Can you add a sample of the code you're using?
Comments.UserDisplayName: Alex Roper
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-14T23:44:11.443Z
Comments.Text: It is a simple search: I set a variable called "q" and use that as the search parameter, e.g.  craft,entries,section('rides').search(q) If that variable contains more than one dash it does not return anything - if I edit the slug to one dash it works fine
Comments.UserDisplayName: Roi Agneta
Tags: <search><entry-slug>
Title: Search using Slug as query parameter
ThreadText: # Search using Slug as query parameter
  
  (Asked by: username_0 on 2018-09-14)
  
  I created Search that uses entry slug, but it fails if the slug has more than one dash "-" in it. Has anyone come across this and/or have any ideas for getting around it?
  
  I need to use the slug because they are unique within a section.
  
  **Tags:** search, entry-slug
  
  > **Comments:**
  > **username_1**: Can you add a sample of the code you're using?  
  > **username_0**: It is a simple search: I set a variable called "q" and use that as the search parameter, e.g.  craft,entries,section('rides').search(q) If that variable contains more than one dash it does not return anything - if I edit the slug to one dash it works fine  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-16. Score: 1
  
  If you know your **q** variable should be a slug, you can use the `.slug` query parameter:
  
  ```
  {# Get the requested entry slug from the URL #}
  {% set requestedSlug = craft.app.request.getSegment(3) %}
  
  {# Fetch the entry with that slug #}
  {% set entry = craft.entries()
      .slug(requestedSlug|literal)
      .one() %}
  
  ```
  
  [More on how to use this in the Craft 3 docs](https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#slug).
  
  I have personally had some unexpected results using Craft's built-in search.
  
  > **Comments:**
  > **username_0**: Thanks, username_1 . I ended up taking a different approach using relatedTo. Appreciate your response!  
  
  ---
  
  