Title: Lists Posts Alphabetically
Last modified: August 19, 2016

---

# Lists Posts Alphabetically

 *  [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/)
 * I’m wanting to list posts by category id and then alphabetically, for example
   category-4.php would have
 * **A**
    Apples Destroys Microsoft
 * **B**
    Batman Destroys Joker
 * WP-Snap! is not what I’m looking for, I need everything on one page instead of
   letter pages like WP-Snap! does it. Thanks.

Viewing 13 replies - 1 through 13 (of 13 total)

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670229)
 * Note: I’ve deleted your duplicate forum posts on this topic. In the future, do
   not post multiple times on the same issue.
 * For your request, take a look at the Custom Query String plugin found here:
 * [http://www.transycan.net/blogtest/download-themes/](http://www.transycan.net/blogtest/download-themes/)
 * You can set it to sort posts by title, even on just specific categories if you
   wish.
 *  Thread Starter [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670283)
 * That doesn’t do what I’m looking for, it just does the samething this does <?
   php query_posts(‘showposts=-1&orderby=title&order=ASC’); ?>
 * That would work if it showed a big bold alphabet letter before it begins each
   title section. Any other plugins you might know of or custom coding? Thanks for
   the help so far.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670299)
 * I know of no plugin that does this. However, some custom coding:
 * [http://wordpress.pastebin.com/f524c9f4](http://wordpress.pastebin.com/f524c9f4)
 * Version that only displays letter heading when one or more posts fall under it:
 * [http://wordpress.pastebin.com/f2302b7cb](http://wordpress.pastebin.com/f2302b7cb)
 *  Thread Starter [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670301)
 * Okay I placed the following code in category.php
 *     ```
       <?php
   
       $posts = new WP_Query("cat=$cat&orderby=title&order=ASC&showposts=-1");
       if ($posts->have_posts()) :
       	for($i='A';$i!='AA';$i++) :
       ?>
       <?php
       		while ($posts->have_posts()) :
       			$posts->the_post();
       			if( $i == strtoupper(trim(substr($post->post_title, 0, 1))) ) :
       				if( !$a_z_header ) :
       					$a_z_header = 1;
       ?>
       <h3 id="<?php echo $i; ?>"></a><?php echo $i; ?></h3>
       	<ul>
       <?php
       				endif;
       ?>
       	<li><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
       <?php
       			endif;
       		endwhile;
       ?>
       	</ul>
       <?php
       		$a_z_header = 0;
       	endfor;
       endif;
       ?>
       ```
   
 * And got the following errors:
 * WordPress database error: [Table ‘vgarchives.wp_categories’ doesn’t exist]
    SELECT
   cat_ID FROM wp_categories WHERE category_nicename = ‘xbox’
 * Warning: Cannot modify header information – headers already sent by (output started
   at /home/content/s/h/o/shockon/html/vgarchives/wp-includes/wp-db.php:160)
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670303)
 * What version of WordPress are you running?
 *  Thread Starter [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670304)
 * 2.3.1 the latest one.
 *  Thread Starter [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670305)
 * Okay now it’s sort of working. [http://www.vgarchives.com/category/xbox/](http://www.vgarchives.com/category/xbox/)
   gives you one error [http://vgarchives.com/category/xbox/](http://vgarchives.com/category/xbox/)
   gives you two errors.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670307)
 * Couple issues:
 * 1. The categories table *doesn’t* exist in 2.3. It was around in 2.2 and previous,
   but was replaced with the terms table (more or less). See here:
 * [http://boren.nu/archives/2007/08/26/wordpress-23-taxonomy-schema/](http://boren.nu/archives/2007/08/26/wordpress-23-taxonomy-schema/)
 * 2. My code doesn’t do anything more than adopt the query as it already exists
   in WordPress. Do you have any queries occurring in your template(s) outside what
   I provided? Any category-related plugins?
 *  Thread Starter [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670308)
 * Nope I don’t have any other category plugins or queries inside of category.php
 * What would have to be done for the code you gave me to work properly? I’m not
   much of an mysql expert so I don’t really know what to edit in the code but what
   you gave me is what I’m looking for exactly minus the errors of course.
 *  Thread Starter [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670309)
 * Ahh it works now! 🙂 I had the custom query plugin turned on, I turned it off
   and boom it works perfect now! Thanks for the help on this, things should run
   smooth even on new upgrades of wordpress correct?
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670311)
 * “_things should run smooth even on new upgrades of wordpress correct?_“
 * As long as the WP_Query class isn’t greatly overhauled (unlikely for the time
   being) or the global $cat is removed (again unlikely, but you never know about
   our WP devs… `:}` ).
 *  Thread Starter [invisionblue](https://wordpress.org/support/users/invisionblue/)
 * (@invisionblue)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670312)
 * Alright thanks, I now have everything working properly as you can see [http://www.vgarchives.com/category/xbox/](http://www.vgarchives.com/category/xbox/)
   when you click on a letter the game will appear. Thanks and have a nice Christmas.
 *  [arstuavitamea](https://wordpress.org/support/users/arstuavitamea/)
 * (@arstuavitamea)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670515)
 * i need help to make a query to have post listed Alphabetically by a custom field(
   eg. Surname)
 * thiis is the query i use to sort the post normally ORDERBY Surname..
 *     ```
       $querystr = "
       SELECT * FROM $wpdb->posts
       LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
       LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
       LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
       WHERE $wpdb->term_taxonomy.term_id = 42
       AND $wpdb->term_taxonomy.taxonomy = 'category'
       AND $wpdb->posts.post_status = 'publish'
       AND $wpdb->postmeta.meta_key = 'surname'
       ORDER BY $wpdb->postmeta.meta_value ASC
       ";
   
        $pageposts = $wpdb->get_results($querystr, OBJECT);
       ```
   
 * my dream is to add a line with all letters A-Z where to click and filter by that
   letter (wp-snap style)
 * thanks in advance
 * CODE IS POETRY
    SIMPLE CODE IS ART

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Lists Posts Alphabetically’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 13 replies
 * 3 participants
 * Last reply from: [arstuavitamea](https://wordpress.org/support/users/arstuavitamea/)
 * Last activity: [17 years, 7 months ago](https://wordpress.org/support/topic/lists-posts-alphabetically/#post-670515)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
