Search by ID
-
Hi, I previously used this code:
<?php new WPkonsulentSearchById(); class WPkonsulentSearchById { function __construct() { add_filter('posts_where', array($this, 'posts_where')); } function posts_where($where) { if(is_search()) { $s = $_GET['s']; if(!empty($s)) { if(is_numeric($s)) { global $wpdb; $where = str_replace('(' . $wpdb->posts . '.post_title LIKE', '(' . $wpdb->posts . '.ID = ' . $s . ') OR (' . $wpdb->posts . '.post_title LIKE', $where); } elseif(preg_match("/^(\d+)(,\s*\d+)*\$/", $s)) // string of post IDs { global $wpdb; $where = str_replace('(' . $wpdb->posts . '.post_title LIKE', '(' . $wpdb->posts . '.ID in (' . $s . ')) OR (' . $wpdb->posts . '.post_title LIKE', $where); } } } return $where; } } ?>
It is to search for products by id. After activating your plugin, the code stopped working. How to combine them? Thank you.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Search by ID’ is closed to new replies.