SOLVED

Need help in SP Modern Site for searching associated sites on homepage of a HubSite

Copper Contributor

Hello,
In my tenant there is one HubSite "MainHubSite". And there are some other communications sites A,B,C,D,E,F,G,H etc. which are associated with "MainHubSite".
My requirement is on Homepage of "MainHubSite", I want to have interface where I can search associated site's name and below that it will show result accordingly. If nothing is searched then it should display all the associated sites. Now, what I did is = On homepage of "MainHubSite", I am using "PnP search box" and "PnP search results" webparts. And below that I am using "Sites" webpart where I am successfully able to display all associated sites. But when I search something in PnP Searchbox, I am not getting those associated sites.
I am using query "{searchboxquery} Sites contentclass: STS_Site " in PnP search result webpart's query parameter. Here, Sites is name of Sites webpart. (I should fetch associated sites from sites webpart or not I am not sure)


Can anyone please help me to get this resolved? I tried so many things but unable to understand where it's going wrong. Thanks in advance!
@ganeshsanap sir tagging you if you can help. Thanks :)

3 Replies
best response confirmed by iamajaythakur (Copper Contributor)
Solution

@iamajaythakur Instead of using "Sites" in search query, use hub site DepartmentId as mentioned in this thread: How can I search for sites within my hub using PnP Modern Search? 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

Hi Ganesh Sir,
Thank you, it helped me to display all the associated sites on Homepage of Hubsite using PnP - Search Results webpart.
@ganeshsanap sir, Can we have functionality here like below?
If we reload the homepage, PnP results webpart should show all associated sites and if I search a site then it should filter out that site. Current query either shows all sites or it doesn't show any but filter out the site which we search. Can both be done at same time? I didn't find anything that will help me apply condition on the query.
1 best response

Accepted Solutions
best response confirmed by iamajaythakur (Copper Contributor)
Solution

@iamajaythakur Instead of using "Sites" in search query, use hub site DepartmentId as mentioned in this thread: How can I search for sites within my hub using PnP Modern Search? 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

View solution in original post