summaryrefslogtreecommitdiff
path: root/WP/search-by-title-with-wp-query.php
blob: 418f0575f1c2696faaa3d2c82f3520b40cfac958 (plain)
1
2
3
4
5
6
7
8
9
10
11
<?php

// Add posts_where filter for title_like
add_filter('posts_where', function ($where, \WP_Query $wp_query) {
  if ($title = $wp_query->get('title_like')) {
    global $wpdb;
    $where .= " AND {$wpdb->posts}.post_title LIKE '" . esc_sql($wpdb->esc_like($title)) . "'";
  }

  return $where;
}, 10, 2);