ListingActions.php
25 lines
| 1 | <?php namespace NestedPages\Entities\Listing; |
| 2 | |
| 3 | class ListingActions { |
| 4 | |
| 5 | |
| 6 | public function __construct() |
| 7 | { |
| 8 | add_filter( 'posts_where', array($this, 'titleSearch'), 10, 2 ); |
| 9 | } |
| 10 | |
| 11 | |
| 12 | /** |
| 13 | * For performing search query on titles |
| 14 | */ |
| 15 | public function titleSearch( $where, $wp_query ) |
| 16 | { |
| 17 | global $wpdb; |
| 18 | if ( $post_title_like = $wp_query->get( 'post_title_like' ) ){ |
| 19 | $like = $wpdb->esc_like( $post_title_like ); |
| 20 | $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $like ) . '%\''; |
| 21 | } |
| 22 | return $where; |
| 23 | } |
| 24 | |
| 25 | } |