Skip to content

Instantly share code, notes, and snippets.

@jeremiahbratton
jeremiahbratton / query-by-first-character.php
Created March 21, 2018 17:21
WordPress Posts Where Filter - Query by first character of post title
add_filter('posts_where', 'first_character_posts_where' );
function first_character_posts_where($where) {
global $wpdb;
//Take in a URL parameter
$alpha_filter = sanitize_text_field( $_GET['alpha'] );
// throw a different regex where at the database depending on if we want numbers or a specific character
if( $alpha_filter !== false && $alpha_filter == 'number' ) {