Pages

Feb 18, 2016

how to append (add) custom filter with get_post query in wordpress

Append custom filter with get_post query in wordpress


add_filter( 'posts_where', 'wpse00001_posts_where', 10, 2 );
function wpse00001_posts_where( $where, &$wp_query )
{
global $wpdb;
if ( $wpse00001_title = $wp_query->get( 'wpse00001_title' ) ) {
$where .= ' AND UPPER(' . $wpdb->posts . '.post_title) LIKE UPPER(\'%' . esc_sql( $wpdb->esc_like( $wpse00001_title ) ) . '%\')';
}
return $where;

}

No comments: