Title: Parse Post Title
Last modified: August 18, 2016

---

# Parse Post Title

 *  Resolved [codecottage](https://wordpress.org/support/users/codecottage/)
 * (@codecottage)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/parse-post-title/)
 * I have a set of posts with titles like this:
 * 20071121 November 21, 2007
 * I’d like to strip out the numeric date (used for sorting) and leave the date 
   in words. The date shows up with the numbers but I don’t even think that it has
   even gotten to the point where I attempt to reformat it.
 * **Code**
 *     ```
       $postslist = get_posts('numberposts=10&order=ASC&orderby=post_title');
       foreach ($postslist as $post) :
          setup_postdata($post);
          $mypost_title = the_title();
          $datewords = preg_split("/[\s]+/", $mypost_title);
          echo $datewords[1] . " " . $datewords[2] . " " . $datewords[3];
         the_excerpt();
         echo "<br />";
       endforeach;
       ```
   
 * **Output:**
 * [http://test1.handcraftedsites.com/index.php](http://test1.handcraftedsites.com/index.php)
 * Thank you for your help!
 * Elizabeth

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

 *  Thread Starter [codecottage](https://wordpress.org/support/users/codecottage/)
 * (@codecottage)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/parse-post-title/#post-656889)
 * I found the answer using Google instead of the WordPress.org search function.
   Here it is:
 * I found the syntax for the_title and here’s the revised line
    OLD VERSION: $mypost_title
   = the_title(); NEW VERSION: $mypost_title = the_title(”,”,false);
 * I modified the first line as well to use query_posts.
    Here’s the new code in
   its entirety:
 * $postslist = query_posts(‘cat=7&order=DESC’);
    foreach ($postslist as $post) :
   setup_postdata($post); $mypost_title = the_title(”,”,false); $datewords = preg_split(“/[\
   s]+/”, $mypost_title); echo $datewords[1] . ” ” . $datewords[2] . ” ” . $datewords[
   3]; the_excerpt(); echo ““; endforeach;
 * The info on the syntax for the_title is at:
    [http://codex.wordpress.org/Template_Tags/the_title](http://codex.wordpress.org/Template_Tags/the_title)
 *  Thread Starter [codecottage](https://wordpress.org/support/users/codecottage/)
 * (@codecottage)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/parse-post-title/#post-656956)
 * This scheme has one serious fallacy I discovered later! The data in the title
   is **string** data and hence the numbers weren’t being sorted properly.
 * Instead, I am making a calendar using pages (not posts) and placing the dates
   in the menu order box on the page development screen. (ex. 20070405) I sort on
   menu order and it works great. No need to write any extra code!

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

The topic ‘Parse Post Title’ is closed to new replies.

 * 2 replies
 * 1 participant
 * Last reply from: [codecottage](https://wordpress.org/support/users/codecottage/)
 * Last activity: [18 years, 6 months ago](https://wordpress.org/support/topic/parse-post-title/#post-656956)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
