• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Search only threads and posts from search_bar

#1
Since searching profile posts are pretty much useless, I would like to search only threads and posts from the search_bar. Which would also enable Show results as threads from the front page.

Did anyone successfully do this?
 

Jake Bunce

XenForo moderator
Staff member
#2
Admin CP -> Appearance -> Templates -> search_bar

Add the red code (two pieces):

Code:
<xen:edithint template="search_bar.css" />

<div id="searchBar" class="pageWidth">
	<xen:hook name="quick_search">
	<fieldset id="QuickSearch">
		<form action="{xen:link 'search/search'}" method="post" class="formPopup">
			
			<div class="primaryControls">
				<!-- block: primaryControls -->
				<input type="search" name="keywords" value="" class="textCtrl" placeholder="{xen:phrase search}..." results="0" title="{xen:phrase enter_your_search_and_hit_enter}" id="QuickSearchQuery" />				
				<!-- end block: primaryControls -->
			</div>
			
			<div class="secondaryControls">
				<div class="controlsWrapper">
				
					<!-- block: secondaryControls -->
					<dl class="ctrlUnit">
						<dt></dt>
						<dd><ul>
							<li><label><input type="checkbox" name="title_only" value="1"
								id="search_bar_title_only" class="AutoChecker"
								data-uncheck="#search_bar_thread" /> {xen:phrase search_titles_only}</label></li>
						</ul></dd>
					</dl>
				
					<dl class="ctrlUnit">
						<dt><label for="searchBar_users">{xen:phrase posted_by_member}:</label></dt>
						<dd>
							<input type="text" name="users" value="" class="textCtrl AutoComplete" id="searchBar_users" />
							<p class="explain">{xen:phrase separate_names_with_comma}</p>
						</dd>
					</dl>
				
					<dl class="ctrlUnit">
						<dt><label for="searchBar_date">{xen:phrase newer_than}:</label></dt>
						<dd><input type="date" name="date" value="" class="textCtrl" id="searchBar_date" /></dd>
					</dl>
					
					<xen:if is="{$searchBar}">
					<dl class="ctrlUnit">
						<dt></dt>
						<dd><ul>
								<xen:foreach loop="$searchBar" value="{$constraint}">
									<li>{xen:raw $constraint}</li>
								</xen:foreach>
						</ul></dd>
					</dl>
					<xen:else />
					<dl class="ctrlUnit">
						<dt></dt>
						<dd><ul>
							<li><label><input type="checkbox" name="group_discussion" value="1" /> {xen:phrase display_results_as_threads}</label></li>
						</ul></dd>
					</dl>
					</xen:if>
				</div>
				<!-- end block: secondaryControls -->
				
				<dl class="ctrlUnit submitUnit">
					<dt></dt>
					<dd>
						<input type="submit" value="{xen:phrase search}" class="button primary Tooltip" title="{xen:phrase find_now}" />
						<div class="Popup" id="commonSearches">
							<a rel="Menu" class="button NoPopupGadget Tooltip" title="{xen:phrase useful_searches}" data-tipclass="flipped"><span class="arrowWidget"></span></a>
							<div class="Menu">
								<div class="primaryContent menuHeader">
									<h3>{xen:phrase useful_searches}</h3>
								</div>
								<ul class="secondaryContent blockLinksList">
									<!-- block: useful_searches -->
									<li><a href="{xen:link find-new/threads, '', 'recent=1'}">{xen:phrase recent_threads}</a></li>
									<xen:if is="{$visitor.user_id}">
									<li><a href="{xen:link search/member, '', 'user_id={$visitor.user_id}', 'content=thread'}">{xen:phrase your_threads}</a></li>
									<li><a href="{xen:link search/member, '', 'user_id={$visitor.user_id}', 'content=post'}">{xen:phrase your_posts}</a></li>
									<li><a href="{xen:link search/member, '', 'user_id={$visitor.user_id}', 'content=profile_post'}">{xen:phrase your_profile_posts}</a></li>
									</xen:if>
									<!-- end block: useful_searches -->
								</ul>
							</div>
						</div>
						<a href="{xen:link search}" class="button moreOptions Tooltip" title="{xen:phrase advanced_search}" data-offsetx="-100">{xen:phrase more}...</a>
					</dd>
				</dl>
				
			</div>

			<input type="hidden" name="type" value="post" />
			<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
		</form>		
	</fieldset>
	</xen:hook>
</div>
 
#3
Fantastic. Thanks :)

Show results as threads should probably be available from within forums, but I guess that would require a bit more heavy modifications
 

Ludachris

Well-known member
#9
Hey @Jake Bunce - wanted to see if there was a different way to change the code in the search_bar template to make it not break the "Search This Thread Only" option, maybe with a conditional or something. I'd like to make it so that the default search bar option is to display results as threads outside of browsing a forum or a thread.