Dotclear

Vous n'êtes pas identifié(e).

Annonce

13 février 2024 Sortie de Dotclear 2.29

#1 2016-01-29 09:45:57

tezcatlipoca
Membre
Inscription : 2016-01-29

Filtering the Search function

Hello fellow DotClear users!

I am a recent user of DotClear, having found it after searching for alternatives to the abysmal Wordpress, and am thoroughly loving it so far.
It's clean, fast and - most importantly for me - doesn't try to 'help' and mangle my HTML/PHP code.

Because I'm still discovering DotClear this is possibly a bit of a newcomer question, but I've searched through this forum and the knowledgebase and can't seem to find the answer anywhere so would appreciate the benefit of other users' experience.

The problem is the in-built Search function used by the visitors to a DotClear site. This is the widget that sits in the sidebar of most themes and allows users to make word searches across the DotClear site.
This widget works just fine and there is no issue with it, but in testing my site the search is returning results for all the Entries (which I want) and all the Pages (which I don't want).

I've been through all the settings I can find and there doesn't seem to be a way to control it.
I've also looked through the code since I'm assuming at some point that widget must perform an SQL lookup on the attached database. If I can find that lookup I can easily reprogram it with a WHERE clause to ignore the Pages but I've not been able to locate that anywhere in the code so far.

So, simple question: Is there a way to filter what this Search widget hunts for?


Thank you in advance for any help you can give!

Hors ligne

#2 2016-01-29 11:58:20

pierrevg
Membre
Inscription : 2005-04-13
Site Web

Re : Filtering the Search function

Bonjour,

Url de ton blog ?
Chez moi, le widget de recherche ne recherche que dans les billets et aucunement dans les pages...
Version de ton dc ?

Hors ligne

#3 2016-01-29 12:03:26

Franck
Footer de merde
Lieu : Paris
Inscription : 2004-11-09
Site Web

Re : Filtering the Search function

Hi,

In your theme, create (if it doesn't exist, otherwise add the following code but the first two lines) a _public.php file with this content :

<?php
if (!defined('DC_RC_PATH')) { return; }

$core->addBehavior('coreBlogBeforeGetPosts',array('myBehaviors','coreBlogBeforeGetPosts'));
class myBehaviors
{
	public static function coreBlogBeforeGetPosts($params)
	{
		global $core;
		if ($core->url->type == 'search') {
			// Search in posts only (excluding pages)
			$params['post_type'] = array('post');
		}
	}
}

It should work


Dotclear addicted since 2004

Hors ligne

#4 2016-01-29 13:50:06

tezcatlipoca
Membre
Inscription : 2016-01-29

Re : Filtering the Search function

@Franck

Your PHP code worked perfectly and my Search widget will now only get results from the Post type.
Thank you so much!

Hors ligne

#5 2016-01-29 14:01:10

Franck
Footer de merde
Lieu : Paris
Inscription : 2004-11-09
Site Web

Re : Filtering the Search function

tezcatlipoca a écrit :

@Franck

Your PHP code worked perfectly and my Search widget will now only get results from the Post type.
Thank you so much!

You're welcome!


Dotclear addicted since 2004

Hors ligne

#6 2016-02-01 02:17:09

ben_griffith
Membre
Lieu : Wiltshire
Inscription : 2009-09-28

Re : Filtering the Search function

Many thanks for that code, Franck. Just saved it in my archive.
BTW, searching through pages came with 2.8. It didn't happen with 2.7 as far as I remember. Please don't do the same "improvement" as Wordpress back then.

One of reasons why I changed from Wordpress to Dotclear back then was that with Wordpress 2.6, suddenly the search listed content in directories. For example, if I searched for "galleries" in my blog (which were 3 entries), it listed each single picture in my folder "galleries". I called it a bug, they called it feature. Search became completely useless over night.


I Dotclear.

Hors ligne

Vous n'êtes pas identifié(e).

Pied de page des forums

Sites map