How To Select Category Also in SQL Query
-
I have a function that returns posts by letter. Used for browsing a large database by letters. But I want to be able to only return the posts in a certain category and since that is in another table I get confused.
Below is the query that I am running right now that returns all categories.
$letters = $wpdb->get_col( "SELECT DISTINCT LEFT(post_title,1) AS first_letter FROM $wpdb->posts WHERE post_type = '$post_type' AND post_status = 'publish' ORDER BY first_letter ASC" );
I guess I could either fix the query or do a check for displaying if the category equals a certain ID. Here is my loop for showing the letters.
<?php foreach ($letters as $letter) { $url = add_query_arg('first_letter',$letter,$pageURL); echo "<a href='$url' title='Starting letter $letter' >$letter</a> "; } ?>
Any help is greatly appreciated.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How To Select Category Also in SQL Query’ is closed to new replies.