I use WordPress to run an events site that people can sign down to if they have a subscription.

At the bottom of each event, if you are admin you can see a guest list with Name, Email, Tel, Avatar (through BuddyPress) and for our information your subscription details.

Subscription details are stored as Custom Posts & what I want to do is simply list, in date form when they first started their subscription.

The subscription expiry seems to be pretty easy as it's stored as a meta key but I cannot get the thing to display individual post publish dates for each of the custom posts called.

This is what I have so far: It's probably a bit rough and ready but I've only taught myself PHP over the last month or so since the website launched so please bear with me.

    <th>User (Full Name)</th>
    <th>Email Address</th>
    <th>Subscriber</br> Since</th>
  <?php foreach($tickets as $ticket) { ?>
      <td><?php echo $ticket['name']; ?>
          <?php $useremail = $ticket['email'];
              $user = get_user_by( 'email', $useremail );
              $IDuser = $user->ID;
              echo bp_get_profile_field_data( array( 'field'=>'Full (Legal) Name - Not Displayed*','user_id'=>$IDuser));
      <td><?php echo $ticket['email']; ?></td>
      <td><?php $useremail = $ticket['email'];
          $user = get_user_by( 'email', $useremail );
          $IDuser = $user->ID;
          $telno = bp_get_profile_field_data( array( 'field'=>'Mobile phone number - Not Displayed*','user_id'=>$IDuser));
          {?><a href="tel:<?php echo $telno;?>"><?php echo $telno; }?></a>
      <td><?php $useremail = $ticket['email'];
          $user = get_user_by( 'email', $useremail );
          $IDuser = $user->ID;
          echo getSubscriberType($IDuser);
          $subscriptions = getUserSubscriptions($IDuser);?></br> 
          <?php echo date('d/m/Y',strtotime($subscriptions[0]['expiry'])); ?>
      <!-- (not in actual code) - GETING THE USERS FIRST PUBLISHED SUBSCRIPTION?? \/   \/   \/   \/  -->
          $useremail = $ticket['email'];
          $user = get_user_by( 'email', $useremail );
          $IDuser = $user->ID;
          $subscriptions = getUserSubscriptions($IDuser);
          echo get_the_date('M j, Y', $subscriptions);
      <!-- (not in actual code) - GETING THE USERS FIRST PUBLISHED SUBSCRIPTION?? /\   /\   /\   /\ -->
      <td><?php $useremail = $ticket['email'];
          $user = get_user_by( 'email', $useremail );
          $IDuser = $user->ID;
          echo get_avatar( $IDuser, 60); ?>

So the bit between the comments seems to show the same date for everyone not the individual Subscription post it's called.... The call above;

<?php echo date('d/m/Y',strtotime($subscriptions[0]['expiry'])); ?> works fine but I'm calling a specific meta key. As far as I understand, wordpress does not have a specific key for calling this data...?

If anyone could help that would be fantastic as there's lots of help out there for calling timestamps on the page you're on or for specific post ID's but nothing with this style of call.


EDIT: Tried to implement the code show in duplicate answer but makes no sense - I'm not looking to show all posts as a list as there is plenty of blogs to help with that. I want to query my subscription CPT with the user ID found by taking it from the metadata off the Ticket CPT. The only thing that links the two CPTs is the UserID...

What I'm struggling with is how to query and match the two Custom Posts to finally give the first Publish date of the subscription. Sorry it's a bit long winded - any help would be hugely appreciated.

  • Seems like you want to get the publish date of a custom post type outside of the loop (subscription is a CPT, correct?). If so, see wordpress.stackexchange.com/questions/55739/… Feb 14, 2014 at 13:22
  • Subscriptions & Tickets are posted in the system as CPTs yes... I had a look at that post and (forgive my limited knowledge) didn't think that it helped my scenario. The trouble is as the tickets and subscriptions are separate tables I have to query one with the data from the other - not just the general Wordpress database. In my case I used the email address associated with the ticket to match the user ID and then go from there. Thanks for your reply - I just think I need a little more guidance!
    – Bysander
    Feb 14, 2014 at 13:45
  • Without knowledge of the infrastructure, I can't help further. But if a subscription is a CPT, then just pull the subscription (post) ID and use the get_the_time(). Feb 14, 2014 at 13:47
  • Hi Stephen, (if you're still there). Would you please be able to poke me in the right direction as how to call the postID using other meta data in the custom post outside the loop as every blog or guide seems to rely on the fact you know the postID first... Struggling to get my head round it. Thank you so much, really appreciate your help
    – Bysander
    Feb 18, 2014 at 11:30
  • If you want to search for CPTs satisfying a meta data query see WP_Query codex. Otherwise you might want to look around the site / ask a new question. Feb 18, 2014 at 13:10

1 Answer 1


OK so was way simpler than I thought in the end and didn't involve a query of query.

The same can be achieved like this:

$useremail = $ticket['email'];
$user = get_user_by( 'email', $useremail );
$IDuser = $user->ID;
$args = array(
              'posts_per_page' => 1,
              'post_type' => 'subscription',
              'author' => $IDuser,
              'meta_key' => 'state',
              'meta_value' => 'complete',
              'orderby' => 'date',
              'order' => 'ASC',
$first_post = new WP_Query($args);
//    '<pre>'.print_r($first_post).'</pre>'; // You can use this to check what the query produces to make sure you're on the right track.
if ($first_post->have_posts()) {

    the_time('M j, Y');


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.