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