Custom database query example Print

  • 0

Wordpress custom database query example:

<ul
class="posts"><?php global $wpdb; $request ="a"// could be any letter you want $results = $wpdb->get_results(" SELECT * FROM $wpdb->posts WHERE post_title LIKE '$request%' AND post_type = 'post' AND post_status = 'publish'; ");if( $results ){foreach( $results as $post ){ setup_postdata ( $post );?><li> ... loop stuff here (the_title, the_permalink) ... </li><?php }}else{?><divclass="alert">No clubs found for that letter. Please try again, or use the search at the top.</div><?php }?></ul>

Was this answer helpful?

« Back