Plugin Directory

Changeset 2651363


Ignore:
Timestamp:
12/31/2021 11:47:01 AM (4 years ago)
Author:
tsinf
Message:

v1.0.2 Fix bug, that other search parameters in admin area are ignored when slug search is activated

Location:
ts-search-slug
Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • ts-search-slug/trunk/plugin.php

    r1899137 r2651363  
    77 Author: Tobias Spiess
    88 Author URI: https://www.spiess-informatik.de
    9  Version: 1.0.1
     9 Version: 1.0.2
    1010 Text-Domain: tsinf_search_plugin_textdomain
    1111 Domain Path: /languages
     
    5454            }
    5555           
    56             add_filter('posts_where' , array('TS_Search_Slug', 'posts_where'));
     56            add_filter('posts_where' , array('TS_Search_Slug', 'posts_where'), 10, 2);
    5757        }
    5858       
     
    196196         * @return string
    197197         */
    198         public static function posts_where($where) {
     198        public static function posts_where($where, &$wp_query) {
    199199            global $pagenow;
    200200           
     
    212212            }
    213213           
    214             if(is_admin() && 'edit.php' === $pagenow && isset($_GET['s']) && ($post_type === 'post' || $post_type === 'page' || in_array($post_type, $activated_cpts)))
     214            if(is_admin() && 'edit.php' === $pagenow && isset($_GET['s']) && is_string($_GET['s']) && strlen($_GET['s']) && ($post_type === 'post' || $post_type === 'page' || in_array($post_type, $activated_cpts)))
    215215            {
    216216                global $wpdb;
    217217               
    218                 $search_term = sanitize_text_field($_GET['s']);
    219                 $search_term_slug = sanitize_title($_GET['s']);
    220                
    221                 $where = "
    222                 AND (
    223                     (
    224                         (" . $wpdb->posts . ".post_title LIKE '%" . $search_term . "%') OR
    225                         (" . $wpdb->posts . ".post_excerpt LIKE '%" . $search_term . "%') OR
    226                         (" . $wpdb->posts . ".post_content LIKE '%" . $search_term . "%') OR
    227                         (" . $wpdb->posts . ".post_name LIKE '%" . $search_term_slug . "%')
    228                     )
    229                 ) 
    230                 AND " . $wpdb->posts . ".post_type = '" . $post_type . "'
    231                 AND (" . $wpdb->posts . ".post_status = 'publish' OR " . $wpdb->posts . ".post_status = 'future' OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'private')     
    232                 ";
     218                $like = '%' . $wpdb->esc_like($_GET['s']) . '%';
     219                $like_term = $wpdb->prepare("({$wpdb->posts}.post_name LIKE %s)", $like);
     220               
     221                $like_search_pattern = $wpdb->prepare("({$wpdb->posts}.post_title LIKE %s)", $like);
     222                $like_search_replace = " " . $like_search_pattern . " OR " . $like_term . " ";
     223               
     224                $where = str_replace($like_search_pattern, $like_search_replace, $where);
    233225            }
    234226           
  • ts-search-slug/trunk/readme.txt

    r2497640 r2651363  
    11=== TS Search Slug ===
    22Contributors: tsinf
    3 Tags: post, slug, order, admin
     3Tags: post, slug
    44Requires at least: 4.8
    5 Tested up to: 5.7
     5Tested up to: 5.8
    66Stable Tag: 4.9
    77Creation time: 01.05.2018
    8 Last updated time: 26.06.2018
     8Last updated time: 29.12.2021
    99
    1010Search for Slug in Admin Post/Page Overview and add Slug Column to Post/Page Overview.
    1111
    1212== Description ==
    13 With this plugin you can search posts and for their slug, see the slug in admin post overview in an additional column and sort by it.
    14 You can search for the slug in admin post ovierview.
     13With this plugin you can search posts and for their slug, see the slug in admin post overview in an additional column and sort by it
    1514
    1615== Installation ==
     
    2120
    2221== Changelog ==
     22* 1.0.2
     23Fix bug, that other search parameters in admin area are ignored when slug search is activated
    2324
    2425* 1.0.1
Note: See TracChangeset for help on using the changeset viewer.