Title: Explode function on post title.
Last modified: August 24, 2016

---

# Explode function on post title.

 *  Resolved [michaelennedy1983](https://wordpress.org/support/users/michaelennedy1983/)
 * (@michaelennedy1983)
 * [11 years ago](https://wordpress.org/support/topic/explode-function-on-post-title/)
 * I am trying to create an engagements list for our band with the soonest gigs 
   at the top.
 * once the date has passed the top post would disappear. i am using the post title
   to show the date of the gig and the venu split by using a delimiter, in this 
   case I am using the vertical line ” | “. I would have a post title such as ” 
   15.06.2015 | Old Trafford”
 * To then split this once it is on the page I want to use the explode function 
   but am having problems. here is the code I have so far for testing,
 *     ```
       <?php
       $posts = get_posts('numberposts=15&order=DESC&orderby=post_time&category_name=Engagement');
   
       if (empty($posts)) {
       echo "<div><div class=news-post><span class=news-title>We have no Engagments booked...</span></div></div>" ;
       } else {
   
        foreach ($posts as $post) : setup_postdata( $post ); 
   
        $ingress = the_title();
        $postex = explode("|", $ingress );
        $date = "$postex[0]";
        $venue = "$postex[1]";
        echo "<br>date = $date <br>";
        echo "venue = $venue<br>";
   
        ?>
   
        <?php echo "title = "; the_title()?>
        <?php echo "<br><br>";
   
        ?>
   
       <?php
       endforeach;
       }
   
       ?>
       ```
   
 * This is not working. It all seems to stem from using the “the_title()” variable.
   If I print this directly it shows the post title but i cant put it into the explode
   function. if i actually declare a post title as a variable eg `$ingress = "15.06.15
   | Old Trafford";` the explode function works perfectly and i can then use the
   two outputs as i need.
 * you can see the above code working [HERE](http://dev.hatfieldband.co.uk/bookings.php)
 * Look at the bottom of the main page, it should split the date and venue variables
   out but it isnt.
 * Im quite inexperienced with PHP so its probably incorrect syntax. if anyone can
   help it would be very much appreciated. Cheers

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years ago](https://wordpress.org/support/topic/explode-function-on-post-title/#post-6139764)
 * regarding this line:
 *     ```
       $ingress = the_title();
       ```
   
 * review when to use `get_the_title()` vs `the_title()` or check the proper use
   of the `'echo'` parameter of `the_title()`
 * [https://codex.wordpress.org/Function_Reference/the_title](https://codex.wordpress.org/Function_Reference/the_title)
   
   [https://codex.wordpress.org/Function_Reference/get_the_title](https://codex.wordpress.org/Function_Reference/get_the_title)
 *  Thread Starter [michaelennedy1983](https://wordpress.org/support/users/michaelennedy1983/)
 * (@michaelennedy1983)
 * [11 years ago](https://wordpress.org/support/topic/explode-function-on-post-title/#post-6139770)
 * Thanks that fixed it.

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

The topic ‘Explode function on post title.’ is closed to new replies.

## Tags

 * [css](https://wordpress.org/support/topic-tag/css/)
 * [explode](https://wordpress.org/support/topic-tag/explode/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [rtfm](https://wordpress.org/support/topic-tag/rtfm/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [michaelennedy1983](https://wordpress.org/support/users/michaelennedy1983/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/explode-function-on-post-title/#post-6139770)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
