Skip to content

Instantly share code, notes, and snippets.

@KeSch
Last active February 4, 2016 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KeSch/11228923 to your computer and use it in GitHub Desktop.
Save KeSch/11228923 to your computer and use it in GitHub Desktop.
Toolbox-Modul um die WordPress-Suche zu filtern.
<?php
/*
Module Name: Seiten von Suche ausschließen
Description: Es werden nur Beiträge bei der WordPress-Suche berücksichtigt. [Frontend]
Author: Kevin Schludermann
Author URI: http://kevinschludermann.com
*/
/* Sicherheitsabfrage */
if ( !class_exists('Toolbox') ) {
die();
}
/* Ab hier kann's los gehen */
function ks_search_filter( $query ) {
if ( $query->is_search ) {
/* Nur Artikel/Beiträge berücksichtigen */
$query->set('post_type', 'post');
}
return $query;
}
/* Funktionsaufruf */
add_action( 'pre_get_posts', 'ks_search_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment