Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
ddc78694e5 | |||
75c0cb0d6d |
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Plugin Name: WP-Multi Search
|
* Plugin Name: WP Multi Search
|
||||||
* Plugin URI: https://git.viper.ipv64.net/M_Viper/WP-Multi-Search
|
* Plugin URI: https://git.viper.ipv64.net/M_Viper/WP-Multi-Search
|
||||||
* Description: Fügt eine Suchfunktion als Shortcode, Widget und Menüeintrag hinzu.(Shortcode: [custom_search])
|
* Description: Fügt eine Suchfunktion als Shortcode, Widget und Menüeintrag hinzu. (Shortcode: [custom_search])
|
||||||
* Version: 1.4
|
* Version: 1.6
|
||||||
* Author: M_Viper
|
* Author: M_Viper
|
||||||
* Author URI: https://m-viper.de
|
* Author URI: https://m-viper.de
|
||||||
* Requires at least: 6.7.2
|
* Requires at least: 6.7.2
|
||||||
@ -11,96 +11,109 @@
|
|||||||
* License: GPL2
|
* License: GPL2
|
||||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
* Text Domain: wp-multi-search
|
* Text Domain: wp-multi-search
|
||||||
* Tags: search Autor-search
|
* Tags: search, author-search
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('ABSPATH')) {
|
if (!defined('ABSPATH')) {
|
||||||
exit; // Sicherheitsmaßnahme
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Textdomain laden
|
/*
|
||||||
|
* WP Multi Toolkit Prüfung
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Funktion zur Überprüfung des WP Multi Toolkit Plugins
|
||||||
|
function wp_multi_search_check_dependency() {
|
||||||
|
if (!function_exists('is_plugin_active')) {
|
||||||
|
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüft, ob WP Multi Toolkit installiert und aktiv ist
|
||||||
|
if (!is_plugin_active('wp-multi-toolkit/wp-multi-toolkit.php')) {
|
||||||
|
add_action('admin_notices', 'wp_multi_search_dependency_notice');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fehlermeldung für Admin-Bereich mit Download-Button
|
||||||
|
function wp_multi_search_dependency_notice() {
|
||||||
|
?>
|
||||||
|
<div class="notice notice-error">
|
||||||
|
<p>
|
||||||
|
<?php _e('Das Plugin "WP Multi Search" benötigt "WP Multi Toolkit", um zu funktionieren. Bitte installieren und aktivieren Sie "WP Multi Toolkit".', 'wp-multi-search'); ?>
|
||||||
|
<a href="https://git.viper.ipv64.net/M_Viper/wp-multi-toolkit/releases" target="_blank" class="button button-primary" style="margin-left: 10px;">
|
||||||
|
<?php _e('WP Multi Toolkit herunterladen', 'wp-multi-search'); ?>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin nur initialisieren, wenn Abhängigkeit erfüllt ist
|
||||||
|
if (wp_multi_search_check_dependency()) {
|
||||||
|
// Hier würde der restliche Plugin-Code folgen
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Optional: Plugin komplett deaktivieren, wenn Abhängigkeit fehlt
|
||||||
|
add_action('admin_init', function() {
|
||||||
|
deactivate_plugins(plugin_basename(__FILE__));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Suchfunktion
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
define('CSP_PLUGIN_VERSION', '1.5');
|
||||||
|
define('CSP_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||||
|
|
||||||
function csp_load_textdomain() {
|
function csp_load_textdomain() {
|
||||||
load_plugin_textdomain('wp-multi-search', false, dirname(plugin_basename(__FILE__)) . '/languages');
|
load_plugin_textdomain('wp-multi-search', false, dirname(plugin_basename(__FILE__)) . '/languages');
|
||||||
}
|
}
|
||||||
add_action('plugins_loaded', 'csp_load_textdomain');
|
add_action('plugins_loaded', 'csp_load_textdomain');
|
||||||
|
|
||||||
// 1️⃣ **Suchformular-Funktion mit integriertem CSS**
|
|
||||||
function csp_search_form() {
|
function csp_search_form() {
|
||||||
ob_start();
|
try {
|
||||||
|
$valid_types = ['all', 'title', 'guest_author'];
|
||||||
$search_type = isset($_GET['search_type']) ? sanitize_text_field($_GET['search_type']) : 'all';
|
$search_type = isset($_GET['search_type']) ? sanitize_text_field($_GET['search_type']) : 'all';
|
||||||
|
if (!in_array($search_type, $valid_types)) {
|
||||||
|
$search_type = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<style>
|
<style>
|
||||||
.csp-search-form {
|
.csp-search-form { display: flex; flex-direction: column; gap: 8px; max-width: 500px; margin: 10px auto; padding: 15px; background: #f8f9fa; border-radius: 15px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); }
|
||||||
display: flex;
|
.csp-search-fields { display: flex; gap: 8px; }
|
||||||
flex-direction: column;
|
.csp-search-form input[type="text"] { flex: 1; padding: 10px; border: 1px solid #ddd; border-radius: 20px; font-size: 16px; }
|
||||||
gap: 8px;
|
.csp-search-type { display: flex; gap: 10px; margin-bottom: 10px; }
|
||||||
max-width: 500px;
|
.csp-search-type label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
|
||||||
margin: 10px auto;
|
.csp-search-type input[type="radio"] { margin: 0; }
|
||||||
padding: 15px;
|
.csp-search-form input[type="submit"] { background: #0073aa; color: white; border: none; padding: 10px 15px; border-radius: 20px; cursor: pointer; font-size: 16px; transition: background 0.3s; }
|
||||||
background: #f8f9fa;
|
.csp-search-form input[type="submit"]:hover { background: #005f8d; }
|
||||||
border-radius: 15px;
|
|
||||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.csp-search-fields {
|
|
||||||
display: flex;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.csp-search-form input[type="text"] {
|
|
||||||
flex: 1;
|
|
||||||
padding: 10px;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
border-radius: 20px;
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.csp-search-type {
|
|
||||||
display: flex;
|
|
||||||
gap: 10px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.csp-search-type label {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.csp-search-type input[type="radio"] {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.csp-search-form input[type="submit"] {
|
|
||||||
background: #0073aa;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
padding: 10px 15px;
|
|
||||||
border-radius: 20px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 16px;
|
|
||||||
transition: background 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.csp-search-form input[type="submit"]:hover {
|
|
||||||
background: #005f8d;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
<form class="csp-search-form" role="search" method="get" action="<?php echo esc_url(home_url('/')); ?>">
|
<form class="csp-search-form" role="search" method="get" action="<?php echo esc_url(home_url('/')); ?>">
|
||||||
<div class="csp-search-type">
|
<div class="csp-search-type">
|
||||||
<label>
|
<label><input type="radio" name="search_type" value="all" <?php checked($search_type, 'all'); ?>><?php _e('Alle Inhalte', 'wp-multi-search'); ?></label>
|
||||||
<input type="radio" name="search_type" value="all" <?php checked($search_type, 'all'); ?>>
|
<label><input type="radio" name="search_type" value="title" <?php checked($search_type, 'title'); ?>><?php _e('Titel', 'wp-multi-search'); ?></label>
|
||||||
<?php _e('Alle Inhalte', 'wp-multi-search'); ?>
|
<label><input type="radio" name="search_type" value="guest_author" <?php checked($search_type, 'guest_author'); ?>><?php _e('Autoren', 'wp-multi-search'); ?></label>
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="radio" name="search_type" value="title" <?php checked($search_type, 'title'); ?>>
|
|
||||||
<?php _e('Titel', 'wp-multi-search'); ?>
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="radio" name="search_type" value="guest_author" <?php checked($search_type, 'guest_author'); ?>>
|
|
||||||
<?php _e('Autoren', 'wp-multi-search'); ?>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="csp-search-fields">
|
<div class="csp-search-fields">
|
||||||
<input type="text" name="s" placeholder="🔍 Suchbegriff eingeben" value="<?php echo esc_attr(get_search_query()); ?>">
|
<input type="text" name="s" placeholder="🔍 Suchbegriff eingeben" value="<?php echo esc_attr(get_search_query()); ?>">
|
||||||
@ -109,98 +122,56 @@ function csp_search_form() {
|
|||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return '<p>' . __('Ein Fehler ist aufgetreten', 'wp-multi-search') . '</p>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2️⃣ **Shortcode für das Suchformular**
|
|
||||||
add_shortcode('custom_search', 'csp_search_form');
|
add_shortcode('custom_search', 'csp_search_form');
|
||||||
|
|
||||||
// 3️⃣ **Suchfeld als Widget**
|
|
||||||
class CSP_Search_Widget extends WP_Widget {
|
class CSP_Search_Widget extends WP_Widget {
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct(
|
parent::__construct('csp_search_widget', __('Suche Widget', 'wp-multi-search'), array('description' => __('Suchfeld mit Optionen für Titel- und Gastautoren-Suche', 'wp-multi-search')));
|
||||||
'csp_search_widget',
|
|
||||||
__('Suche Widget', 'wp-multi-search'),
|
|
||||||
array('description' => __('Suchfeld mit Optionen für Titel- und Gastautoren-Suche', 'wp-multi-search'))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function widget($args, $instance) {
|
|
||||||
echo $args['before_widget'];
|
|
||||||
echo '<h3 class="widget-title">' . __('Suche', 'wp-multi-search') . '</h3>';
|
|
||||||
echo csp_search_form();
|
|
||||||
echo $args['after_widget'];
|
|
||||||
}
|
}
|
||||||
|
public function widget($args, $instance) { echo $args['before_widget'] . '<h3 class="widget-title">' . __('Suche', 'wp-multi-search') . '</h3>' . csp_search_form() . $args['after_widget']; }
|
||||||
|
public function form($instance) { echo '<p>' . __('Keine Einstellungen verfügbar', 'wp-multi-search') . '</p>'; }
|
||||||
|
public function update($new_instance, $old_instance) { return $new_instance; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function csp_register_widget() {
|
function csp_register_widget() { register_widget('CSP_Search_Widget'); }
|
||||||
register_widget('CSP_Search_Widget');
|
|
||||||
}
|
|
||||||
add_action('widgets_init', 'csp_register_widget');
|
add_action('widgets_init', 'csp_register_widget');
|
||||||
|
|
||||||
// 4️⃣ **Einstellungsseite hinzufügen**
|
|
||||||
function csp_add_menu_page() {
|
function csp_add_menu_page() {
|
||||||
add_options_page(
|
add_options_page('WP-Multi-Search Settings', 'WP-Multi-Search', 'manage_options', 'custom-search-settings', 'csp_render_settings_page');
|
||||||
'WP-Multi-Search Settings',
|
|
||||||
'WP-Multi-Search',
|
|
||||||
'manage_options',
|
|
||||||
'custom-search-settings',
|
|
||||||
'csp_render_settings_page'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
add_action('admin_menu', 'csp_add_menu_page');
|
add_action('admin_menu', 'csp_add_menu_page');
|
||||||
|
|
||||||
// 5️⃣ **Einstellungsseite rendern**
|
|
||||||
function csp_render_settings_page() {
|
function csp_render_settings_page() {
|
||||||
|
if (isset($_POST['csp_settings_nonce']) && !wp_verify_nonce($_POST['csp_settings_nonce'], 'csp_settings_save')) {
|
||||||
|
wp_die('Security check failed');
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h1><?php _e('WP-Multi Search Settings', 'wp-multi-search'); ?></h1>
|
<h1><?php _e('WP-Multi Search Settings', 'wp-multi-search'); ?></h1>
|
||||||
<form method="post" action="options.php">
|
<form method="post" action="options.php">
|
||||||
<?php
|
<?php settings_fields('csp_settings_group'); do_settings_sections('custom-search-settings'); wp_nonce_field('csp_settings_save', 'csp_settings_nonce'); submit_button(); ?>
|
||||||
settings_fields('csp_settings_group');
|
|
||||||
do_settings_sections('custom-search-settings');
|
|
||||||
wp_nonce_field('csp_settings_save', 'csp_settings_nonce');
|
|
||||||
submit_button();
|
|
||||||
?>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6️⃣ **Einstellungen registrieren**
|
|
||||||
function csp_register_settings() {
|
function csp_register_settings() {
|
||||||
register_setting('csp_settings_group', 'csp_shiftnav_position');
|
register_setting('csp_settings_group', 'csp_shiftnav_position', array('sanitize_callback' => 'sanitize_text_field'));
|
||||||
|
add_settings_section('csp_main_section', 'ShiftNav Position', 'csp_section_callback', 'custom-search-settings');
|
||||||
add_settings_section(
|
add_settings_field('csp_shiftnav_position_select', 'Select ShiftNav Position', 'csp_shiftnav_position_select_callback', 'custom-search-settings', 'csp_main_section');
|
||||||
'csp_main_section',
|
|
||||||
'ShiftNav Position',
|
|
||||||
'csp_section_callback',
|
|
||||||
'custom-search-settings'
|
|
||||||
);
|
|
||||||
|
|
||||||
add_settings_field(
|
|
||||||
'csp_shiftnav_position_select',
|
|
||||||
'Select ShiftNav Position',
|
|
||||||
'csp_shiftnav_position_select_callback',
|
|
||||||
'custom-search-settings',
|
|
||||||
'csp_main_section'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
add_action('admin_init', 'csp_register_settings');
|
add_action('admin_init', 'csp_register_settings');
|
||||||
|
|
||||||
// 7️⃣ **Callback für die Sektion**
|
function csp_section_callback() { echo __('Choose where to display the search form in ShiftNav:', 'wp-multi-search'); }
|
||||||
function csp_section_callback() {
|
|
||||||
echo __('Choose where to display the search form in ShiftNav:', 'wp-multi-search');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8️⃣ **Callback für das Auswahlfeld**
|
|
||||||
function csp_shiftnav_position_select_callback() {
|
function csp_shiftnav_position_select_callback() {
|
||||||
$positions = array(
|
$positions = array('top' => __('Top of ShiftNav', 'wp-multi-search'), 'bottom' => __('Bottom of ShiftNav', 'wp-multi-search'), 'none' => __('Do not display in ShiftNav', 'wp-multi-search'));
|
||||||
'top' => __('Top of ShiftNav', 'wp-multi-search'),
|
|
||||||
'bottom' => __('Bottom of ShiftNav', 'wp-multi-search'),
|
|
||||||
'none' => __('Do not display in ShiftNav', 'wp-multi-search')
|
|
||||||
);
|
|
||||||
$selected_position = get_option('csp_shiftnav_position', 'none');
|
$selected_position = get_option('csp_shiftnav_position', 'none');
|
||||||
|
|
||||||
echo '<select name="csp_shiftnav_position">';
|
echo '<select name="csp_shiftnav_position">';
|
||||||
foreach ($positions as $value => $label) {
|
foreach ($positions as $value => $label) {
|
||||||
echo '<option value="' . esc_attr($value) . '" ' . selected($selected_position, $value, false) . '>' . esc_html($label) . '</option>';
|
echo '<option value="' . esc_attr($value) . '" ' . selected($selected_position, $value, false) . '>' . esc_html($label) . '</option>';
|
||||||
@ -208,32 +179,19 @@ function csp_shiftnav_position_select_callback() {
|
|||||||
echo '</select>';
|
echo '</select>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9️⃣ **Funktion zum Einfügen des Suchformulars in ShiftNav**
|
|
||||||
function csp_insert_search_form_in_shiftnav($nav_menu, $args) {
|
function csp_insert_search_form_in_shiftnav($nav_menu, $args) {
|
||||||
if ($args->theme_location !== 'shiftnav') {
|
if (!isset($args->theme_location) || $args->theme_location !== 'shiftnav') return $nav_menu;
|
||||||
return $nav_menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
$position = get_option('csp_shiftnav_position', 'none');
|
$position = get_option('csp_shiftnav_position', 'none');
|
||||||
if ($position === 'none') {
|
if ($position === 'none') return $nav_menu;
|
||||||
return $nav_menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
$search_form = '<li class="menu-item">' . csp_search_form() . '</li>';
|
$search_form = '<li class="menu-item">' . csp_search_form() . '</li>';
|
||||||
|
return $position === 'top' ? $search_form . $nav_menu : $nav_menu . $search_form;
|
||||||
if ($position === 'top') {
|
|
||||||
return $search_form . $nav_menu;
|
|
||||||
} elseif ($position === 'bottom') {
|
|
||||||
return $nav_menu . $search_form;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $nav_menu;
|
|
||||||
}
|
}
|
||||||
add_filter('wp_nav_menu_items', 'csp_insert_search_form_in_shiftnav', 10, 2);
|
add_filter('wp_nav_menu_items', 'csp_insert_search_form_in_shiftnav', 10, 2);
|
||||||
|
|
||||||
// 🔟 **Aktualisierte Suchfunktion mit Suchtyp-Unterscheidung**
|
|
||||||
function csp_custom_search_results($query) {
|
function csp_custom_search_results($query) {
|
||||||
if (!is_admin() && $query->is_search() && $query->is_main_query()) {
|
if (!is_admin() && $query->is_search() && $query->is_main_query()) {
|
||||||
|
$query->set('post_status', 'publish');
|
||||||
|
|
||||||
$search_type = isset($_GET['search_type']) ? sanitize_text_field($_GET['search_type']) : 'all';
|
$search_type = isset($_GET['search_type']) ? sanitize_text_field($_GET['search_type']) : 'all';
|
||||||
$search_term = $query->get('s');
|
$search_term = $query->get('s');
|
||||||
|
|
||||||
@ -249,7 +207,7 @@ function csp_custom_search_results($query) {
|
|||||||
array(
|
array(
|
||||||
'key' => '_guest_author',
|
'key' => '_guest_author',
|
||||||
'value' => $search_term,
|
'value' => $search_term,
|
||||||
'compare' => '='
|
'compare' => 'LIKE'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$query->set('meta_query', $meta_query);
|
$query->set('meta_query', $meta_query);
|
||||||
@ -257,7 +215,7 @@ function csp_custom_search_results($query) {
|
|||||||
$query->set('post_type', 'post');
|
$query->set('post_type', 'post');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // 'all'
|
default:
|
||||||
$query->set('_meta_or_title', $search_term);
|
$query->set('_meta_or_title', $search_term);
|
||||||
add_filter('posts_search', 'csp_custom_search_where', 10, 2);
|
add_filter('posts_search', 'csp_custom_search_where', 10, 2);
|
||||||
add_filter('posts_join', 'csp_custom_search_join', 10, 2);
|
add_filter('posts_join', 'csp_custom_search_join', 10, 2);
|
||||||
@ -265,14 +223,17 @@ function csp_custom_search_results($query) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter nach der Abfrage entfernen
|
add_filter('posts_request', function($sql) {
|
||||||
|
error_log('SQL Query: ' . $sql);
|
||||||
|
return $sql;
|
||||||
|
});
|
||||||
|
|
||||||
add_action('wp', function() use ($search_type) {
|
add_action('wp', function() use ($search_type) {
|
||||||
switch($search_type) {
|
switch($search_type) {
|
||||||
case 'title':
|
case 'title':
|
||||||
remove_filter('posts_where', 'csp_title_search_where', 10);
|
remove_filter('posts_where', 'csp_title_search_where', 10);
|
||||||
break;
|
break;
|
||||||
case 'guest_author':
|
case 'guest_author':
|
||||||
// Keine zusätzlichen Filter zum Entfernen
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
remove_filter('posts_search', 'csp_custom_search_where', 10);
|
remove_filter('posts_search', 'csp_custom_search_where', 10);
|
||||||
@ -285,7 +246,6 @@ function csp_custom_search_results($query) {
|
|||||||
}
|
}
|
||||||
add_action('pre_get_posts', 'csp_custom_search_results');
|
add_action('pre_get_posts', 'csp_custom_search_results');
|
||||||
|
|
||||||
// 1️⃣1️⃣ **Hilfsfunktionen für verschiedene Suchtypen**
|
|
||||||
function csp_title_search_where($where, $query) {
|
function csp_title_search_where($where, $query) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
if ($search_term = $query->get('post_title_like')) {
|
if ($search_term = $query->get('post_title_like')) {
|
||||||
@ -302,11 +262,11 @@ function csp_custom_search_where($where, $query) {
|
|||||||
if ($search_term = $query->get('_meta_or_title')) {
|
if ($search_term = $query->get('_meta_or_title')) {
|
||||||
$search = '%' . $wpdb->esc_like($search_term) . '%';
|
$search = '%' . $wpdb->esc_like($search_term) . '%';
|
||||||
$where .= $wpdb->prepare(
|
$where .= $wpdb->prepare(
|
||||||
" OR ({$wpdb->posts}.post_title LIKE %s)
|
" AND ({$wpdb->posts}.post_title LIKE %s
|
||||||
OR ({$wpdb->posts}.post_content LIKE %s)
|
OR {$wpdb->posts}.post_content LIKE %s
|
||||||
OR ({$wpdb->posts}.post_excerpt LIKE %s)
|
OR {$wpdb->posts}.post_excerpt LIKE %s
|
||||||
OR (guest_author.meta_value LIKE %s)
|
OR guest_author.meta_value LIKE %s
|
||||||
OR ({$wpdb->users}.display_name LIKE %s)",
|
OR {$wpdb->users}.display_name LIKE %s)",
|
||||||
$search, $search, $search, $search, $search
|
$search, $search, $search, $search, $search
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -330,7 +290,6 @@ function csp_custom_search_groupby($groupby, $query) {
|
|||||||
return $groupby;
|
return $groupby;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1️⃣2️⃣ **Hilfsfunktion für Gastautoren-Suche**
|
|
||||||
function csp_guest_author_search_where($where, $query) {
|
function csp_guest_author_search_where($where, $query) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
if ($query->get('meta_query')) {
|
if ($query->get('meta_query')) {
|
||||||
@ -338,11 +297,9 @@ function csp_guest_author_search_where($where, $query) {
|
|||||||
SELECT 1 FROM {$wpdb->postmeta}
|
SELECT 1 FROM {$wpdb->postmeta}
|
||||||
WHERE {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID
|
WHERE {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID
|
||||||
AND {$wpdb->postmeta}.meta_key = '_guest_author'
|
AND {$wpdb->postmeta}.meta_key = '_guest_author'
|
||||||
AND {$wpdb->postmeta}.meta_value != ''
|
AND {$wpdb->postmeta}.meta_value LIKE '%" . $wpdb->esc_like($query->get('s')) . "%'
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
return $where;
|
return $where;
|
||||||
}
|
}
|
||||||
add_filter('posts_where', 'csp_guest_author_search_where', 10, 2);
|
add_filter('posts_where', 'csp_guest_author_search_where', 10, 2);
|
||||||
|
|
||||||
?>
|
|
Loading…
x
Reference in New Issue
Block a user