Solved

wordpress archive sort alphabetically

Posted on 2014-10-13
2
271 Views
Last Modified: 2014-10-13
How can I alphabetically sort the posts by title before displaying each post?

Here's the code that I'm using to display the posts in an archive page.
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();

$queried_post = get_post($post_id);
$title = $queried_post->post_title;

echo '<p>'.$queried_post->post_content.'</p>';

endwhile;
endif;
?>

Open in new window


FYI:  I am handling the query in this manner because I need to grab the 'raw' contents of the post (including the HTML tags) - not the usual "display a WP post."  However, if anyone has an improved manner for 'grabbing' the post content, that's fine too.  Basically, any help is appreciated.
0
Comment
Question by:mar2195
  • 2
2 Comments
 

Accepted Solution

by:
mar2195 earned 0 total points
ID: 40379116
I found the answer!

Posting here for others.

(*This goes into your theme's " function.php " file)

<?php
add_filter("posts_orderby", "my_orderby_filter", 10, 2);
function my_orderby_filter($orderby, &$query){
    global $wpdb;
    if (get_query_var("post_type") == "your-post-type") {
         return "$wpdb->posts.post_title ASC";
    }
    return $orderby;
}
?>

Open in new window

0
 

Author Closing Comment

by:mar2195
ID: 40379118
Although this seems to be an easy solution and your would think, an easy to solution find, the answer to this was actually difficult to find.  So I hope this posting helps others.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now