WP Filter Post Title by first Letter, (a b c d e f g)

565 views Asked by At

WP Post Title Image

I need some help with this, The goal is to filter the post titles by letters. If I click "E", It should only show all post titles that starts with "E".

I am wonder if the 'key' for post title is actually 'post_title' I can't seem to get any results. I have attached an image to refer to.

$letter = $_POST['letter'];

$args = array(
        'post_type' => 'directory', 
        'posts_per_page' => -1,     
        'order' => 'asc',       
        'meta_key'=> 'listing',
    );

if(!empty($letter)){
      $args['meta_query'] = array( // tax_query is an array of arrays;        
        array(
          'key' => 'post_title',
          'value' => $letter."%",
          'compare' => 'LIKE',            
        )
      );
    }
$query = new WP_Query( $args ); 
0

There are 0 answers