Filter wordpress post using REGEXP for posts other than A to Z

Asked

Viewed 30 times

0

I would like to know how I can perform a complete filtering process of wordpress posts using regular expressions, so that only show any or all posts that do not have as initial character from A to Z, as numbers, Special characters, letters in Japanese, and any other foreign character, or web symbol.

My code below filters numbers and some special characters, but is not filtering as I reported all types of posts I would like to know how I can stack this function to the code below in the field REGEXP.

if (isset( $_GET['letra'] )) {

if ($_GET['letra'] == '0-9') {
$postids=$wpdb->get_col($wpdb->prepare("
SELECT   ID
FROM     $wpdb->posts
WHERE    $wpdb->posts.post_title REGEXP '^[0-9\$\@\!\?\%\-]'
ORDER BY    $wpdb->posts.post_title")); 
}
else {
$first_char = $_GET['letra'];
$postids=$wpdb->get_col($wpdb->prepare("
SELECT   ID
FROM     $wpdb->posts
WHERE    SUBSTR($wpdb->posts.post_title,1,1) = %s
ORDER BY $wpdb->posts.post_title",$first_char));
}
query_posts(array(
    'post__in'        => $postids,
    'posts_per_page'  => $porPagina,
    'caller_get_posts'=> 1,
    'paged'           => $paginador,
    'post_status'     => 'publish',
    'post_type'       => 'media',
    'meta_key'        => 'modulo_da_media',
    'meta_value'      => 'modo-01',
    'order'           => $ordr,
    'orderby'         => $orde
)); } else {

query_posts(array(
    'posts_per_page'=> $porPagina,
    'paged'         => $paginador,
    'post_status'   => 'publish',
    'post_type'     => 'media',
    'meta_key'      => 'modulo_da_media',
    'meta_value'    => 'modo-01',
    'order'         => $ordr,
    'orderby'       => $orde
));
}
  • 1

    Can use ^[^a-zA-Z] - only that there will catch those who start with anything other than a letter from "a" to "z" (anything even: space, punctuation, letters of other alphabets, emojis, etc) - remembering that it does not take into account accented letters.

  • Thanks for the help, it’s working now perfectly the way I need it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.