Today, at work, I finally got the search on the work website working satisfactorily. It’s something I’ve been struggling with for an age and a half and there were no quick solutions anywhere online, the forums I asked gave no replies, but eventually I cobbled together the bits of php I needed.
None of this will be of any interest to anyone but I’ll carry on regardless (and not post anything too technical), below, bullet-pointed for convenience is the whole sorry story:
The Set Up
- Our website is WordPress based with some bbPress forums (as part of the Commons In A Box plugin collection) forming a large portion of it.
- Some of the WordPress side and most of the bbPress side is only available to logged in subscribers (who are all members of the resources centre).
- The standard WordPress search only includes results from the WordPress side of the site but copes okay with excluding the members-only content.
The Challenge
- We wanted everything to be searchable to users who were logged in and not to the general public.
The Problem
- If we expand the standard search to include results from the forums, the members-only exclusion breaks down because bbPress wasn’t marking topics within private forums as ‘private’.
- These returned search results for topics in private forums, showing the complete contents of the topic.
- When the link back to the topic was clicked, the site would then go to an error page showing an unresolved ‘loop’ giving the (correct) impression that the site wasn’t working properly.
- The bbPress search that appears on the top forum page returns results from all forums, logged in or not in a similar way to the WordPress search.
The Solution
This came in stages with snippets of how to do tiny little bits of it coming from all over the web with a lot of false-starts, swearing and imaginary hair-tearing-out along the way.
- I worked out quite early on that it would be impractical to use the back-end to ensure that all topics inherited their forum privacy settings – especially as our members get to post new topics at will and we don’t have masses of time for moderation.
- The first step was restricting the forum search to appear on each forum page by itself and only search within that forum (with a placeholder text saying ‘search this forum’). This eliminates the final part of the problem above but currently won’t search within subforums – I’d still like to find a way to do this but am happy to leave it as is given that the next steps have worked out as they have.
- I redesigned the side bar to include a better layout, in different sections, with a separate forum search that only appears for logged in users. This was an okay work around as far as it went but was still irritating to have to have two separate search forms needed. This can be seen in action on my test version of the site.
- The bit that has taken most working out was getting the main site search to only include forum results if a user was logged in – I reckon that combined with the new side bar, this should offer a workable solution to the problem as described.
Still to work on
- It more or less does what I want it to, but is a long way from being ideal:
- I have no idea why sub-forums and topics don’t inherit privacy settings or what I’d need to do to make the search exclude private forums unless a user was logged in.
- Search results that are replies to the forum topics are listed as such but no other type of result has a prefix – I’d quite like the forums and forum topics to be identified as such rather than simply appearing as empty posts or posts respectively.
- I’d like to have excerpts of topics from private forums show in the results with the link taking users to a ‘you must be logged in to view this topic’ message rather than the loop-error.
- It would be fantastic if I could find a way to make the individual forum searches include the contents of sub-forums – this is the biggest problem that remains to be sorted but can wait – I’ve spent far too long getting this sorted and I have other work that needs catching up on.
So, there you have it – this has given me more relief than even completing the Giant Form of Doom and getting it handed in.
And I told you it would be dull.
PS if anybody’s interested, I can post about the php bits and pieces with credit to the various bits of internet they were learned about from.