Example
The "mots techniques" plugin adds a technical field to the groups of keywords of SPIP.
When there is no
{technique}
criteria passed to the loop GROUPE_MOTS, the loop automatically filters its results, returning only those where the field
{technique}
is empty. This same feature could also be implemented by creating a function called boucle_GROUPES_MOTS().
function mots_techniques_pre_boucle($loop){
if ($loop->type_requete == 'groupes_mots') {
$table_name = $loop->id_table;
$technical_kw = $table_name .'.technique';
// Select only the loop without the "technical" keyword
if (!isset($loop->modificateur['criteres']['technique']) &&
!isset($loop->modificateur['tout'])) {
$loop->where[]= array("'='", "'$technical_kw'", "'\"\"'");
}
}
return $loop;
}
The array
$loop->where[]
contains arrays with 3 entries: successively being the operator, the field and the value. Here, we add to the query the string
{$table_name}.technique=''
with:
$boucle->where[]= array("'='", "'$technical_kw'", "'\"\"'");