Loop search results with 3.0

Previously I used this to loop search results:

<Loop search="{Url query=s}" >

That’s not working in 3.0 and I don’t see search anywhere in the new docs for loop

Is there a new way to loop search results?

Cheers, Richard

Hey Richard, I love your new user flair haha! :beetle: :mag:

As far as finding this in the docs, I’m pretty sure it can be found in the same place as it was previously, which is in the list of available query parameters for post loops. I believe what your template is doing isn’t so much “looping through search results” as it is using the default loop of the search page and adding a search query parameter that filters results to only show items that match the search terms located in the URL query parameter. The reason you’re not seeing search in the Loop tag section of the docs is that it’s a query parameter for a specific type of loop, not its own loop type.

I know that Eliot changed the way L&L gets its default loop context in a few places in Gutenberg to fix a couple of instances where L&L wasn’t able to loop through the current post, so maybe that impacted how it’s getting its loop context on your search results page. We’ll look into that.

Out of curiosity, if you add type=post to your loop, does that fix/change anything?

Edit: I was able to replicate this and it does indeed seem like a bug. I’ll add this to the to-do list.

1 Like

Maybe I really am an Expert Bug Finder. :grinning:

I’m searching six custom post types, plus the default post type.

Adding type=post shows results from the default post type, but not any of the CPTs.

Cheers, Richard

2 Likes

The type parameter can actually accept an array so if you want a workaround, I’m assuming you could add type=post,quotes,another_post_type,etc to loop through all your post types. It should be functionally the same thing. But I’m sure Eliot will be able to address this quickly so we’ll report back here when there’s an update about this.

1 Like

FYI, adding the other post types does show them on the results page, but FacetWP no longer works to filter the results and my snippet no longer works to sort the results.

Ah, right that makes sense. I didn’t realize you were using FacetWP to filter the search results, which requires using the default loop without any post type specified, so my workaround wouldn’t work for that.

Any idea of the timetable for an update?

@eliot’s communications with me have largely come in the form of LOTR references so I think this would be the best explanation of when we can expect the update. I’ll keep this thread updated about this issue.

2 Likes

I’m looking into the issue, and so far, on my end, the search result page is working with the default loop context using <Loop>.

Here’s the layout template I tried:

<h4>Search results</h4>

<If loop exists>
  <Loop>
    - <Field title /><br>
  </Loop>
<Else />
  Nothing found.
</If>

In the Location tab, I selected it to override the Search Result page. Matching results are showing for all post types.

So I believe this issue (and the other one about search results) are specific to FacetWP.

Could someone give me access to a test site (with FacetWP installed) that I can copy locally to study the issue in depth?

1 Like

I disabled FacetWP. I am using SearchWP

I’m use a Beaver Themer Template for my search results. I added a Tangible Template, plugged in your exact code, i.e.

<If loop exists>
  <Loop>
etc.

and got Nothing found. I tried this:

<Loop search="{Url query=s}" >
- <Field title /><br>

and got nothing.

I tried this:

<Loop type=facts,people,post,product,quotes,goods,memes search="{Url query=s}" >
- <Field title /><br>

Now I see the results, whether FacetWP is disabled or not.

Perhaps if we figured out why your original code isn’t working, the issue of FacetWP would become moot.

@eliot Could you please tell me where to find the Location tab you referenced?

When you create a layout (as opposed to a template) you can select a location where you want the L&L markup to override a part of the theme, which is what Eliot was referring to.

1 Like

Thanks @benjamin I was putting the code written by @eliot into a Beaver Themer Layout, which didn’t work. When I create a Tangible Layout it does work. Is that expected behavior or should the code be expected to work in either location?

If it will only work in a Tangible Layout, I would need to import all the rest of my Beaver Themer page layout into the Tangible Layout.

Ah I understand, so this is specifically an issue with a Beaver Themer template that’s overwriting a search results page. I’m now able to replicate this issue so this should be easier to look into now. I’ll follow up here with updates.

1 Like