-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrp-search.php
74 lines (52 loc) · 1.63 KB
/
mrp-search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// This file is called using AJAX
// when searching for related posts
if( isset( $_GET['mrp_s'] ) ) {
require('../../../wp-config.php');
// Let's keep this a tool for logged in users
if( ! current_user_can("edit_posts") ) {
die('Please log in');
}
global $wpdb;
$s = $wpdb->escape( rawurldecode( $_GET['mrp_s'] ) );
$scope = (int) $_GET['mrp_scope'];
$post_type = $wpdb->escape( $_GET['mrp_post_type'] );
$regexp = "[[:<:]]" . $s;
$where = "";
switch( $scope ) {
case 1 :
$where = "post_title REGEXP '$regexp'";
break;
case 2 :
$where = "post_content REGEXP '$regexp'";
break;
default :
$where = "( post_title REGEXP '$regexp' OR post_content REGEXP '$regexp' )";
break;
}
$query = "SELECT ID, post_title, post_type, post_status FROM $wpdb->posts WHERE $where AND post_type = '$post_type' ";
if( $_GET['mrp_id'] ) {
$this_id = (int) $_GET['mrp_id'];
$query .= " AND ID != $this_id ";
}
$query .= " AND post_status NOT IN ('inherit', 'auto-draft')";
$query .= " ORDER BY post_date DESC LIMIT 50";
$results = $wpdb->get_results( $query );
if( $results ) {
echo "<ul>";
$n = 1;
foreach( $results as $result ) {
echo '<li';
echo ( $n % 2 ) ? ' class="alt"' : '';
echo '> <a href="javascript:void(0)" id="result-'.$result->ID.'" class="MRP_result">';
echo $result->post_title;
if( $result->post_status != 'publish') {
echo ' ('.$result->post_status.')';
}
echo '</a> <a href="'.get_permalink( $result->ID ).'" title="View this post" class="MRP_view_post" target="_blank">›</a></li>';
$n++;
}
echo "</ul>";
}
}
?>