Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm new to coding but love tinkering around (on Virtual Server) with bits to upgrade my current website when I have the time.

What would be really useful to me would be to post an individual attribute of a custom post but most of the support seems to be for showing the whole post.

I have a table of members in an area of my site only available to admin and I would like to post a publish date of their subscription (custom post type 'subscription') in the table.

I already have the $UserID - which should match up to the meta_key 'member' in the Custom Post...

How do I go about echo-ing a publish date in the table when the meta_key 'member' = the userID?

I can post the necessary code I have so far if anyone thinks it helpful... I've been tearing my hair out over this for the last few days as all the code I've tried posts inaccurate dates - either the date of the page or a seemingly random spread that doesn't seem to have any relevance to the individual users.

The table is in a foreach construction.

EDIT: Added Code. GETING THE USERS FIRST PUBLISHED SUBSCRIPTION?? Is the annotated bit I'm having trouble with. I can explain any of the functions if you like too

<?php if (current_user_can('manage_options')) { ?>
<div class="row">
<div class="twelve columns">
  <div class="boxed">
    <h2>Event Administration for event <?php echo get_the_ID(); ?></h2>
    <?php
      $tickets = getTicketsForEvent(get_the_ID()); //EventID through ai1ec-plugin
      <table>
        <thead>
          <tr>
            <th>User (Full Name)</th>
            <th>Email Address</th>
            <th>Phone</th>
            <th>Subscription</br>Expiry/Renewal</th>
            <th>Subscriber</br> Since</th>
            <th>Photo</th>
          </tr>
        </thead>
<tbody>
          <?php foreach($tickets as $ticket) { ?>
            <tr>
              <td><?php echo $ticket['name']; ?>
<br/>(
                <?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));
//this is to get the required field out of BuddyPress profile information filled out
                    ?>)
                </td>
              <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));
//this is to get the required field out of BuddyPress profile information filled out
                    {?><a href="tel:<?php echo $telno;?>"><?php echo $telno; }?></a>
                </td>
                <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'])); ?>
                </td>
// this bit uses some code in function.php just to display the type of subscription. (can also post if required)
<!-- //GETING THE USERS FIRST PUBLISHED SUBSCRIPTION?? \/  \/  \/  \/  \/  -->
<td>
<?php
$useremail = $ticket['email'];
$user = get_user_by( 'email', $useremail );
$IDuser = $user->ID;
global $wpdb;

$post_ids = $wpdb->get_results( "SELECT ID FROM $wpdb->subscriptions WHERE member ='$IDuser'" );

foreach($post_ids as $id){

    $postdate = get_the_date("Y-m-d",$id );
    echo $postdate;
?>
</td>

<!-- //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); ?>
                </td>
            </tr>
          <?php } ?>
        </tbody>
      </table>

Apologies if it's a bit of a mess - I'm no more than an amateur coder....

share|improve this question
    
Yes, please add your code. –  kraftner Feb 18 at 14:02
    
It isn't clear what you are doing. Is "meta_key 'member' = the userID" something in postmeta? Or usermeta? Or a custom table? Exactly which date are you looking for? A post publication date? –  s_ha_dum Feb 18 at 15:19
    
Yes in each custom post the meta key 'member' is the wordpress userID who it's assigned to (ie ticket custom post or subscription custom post). What I want to do is find the publication date of the subscription CP using its meta tag 'member' from the ticket CP.... What's the method - I can only find blogs & tutorials about using a key to show or call whole posts... Where I want to use a meta_key value to call a post and find it's publication date... –  Bysander Feb 19 at 12:28
    
So would go $ticket > get email > email to find userID > find custom post (type 'subscription') that meta_key 'member' = $userID > show publish date of that custom post.... –  Bysander Feb 19 at 14:25
    
Right I think I know a way round it... Is there an easy way of just displaying the first post date of a specific UserID... As the subscriptions post themselves with the author being the userID. –  Bysander Feb 20 at 13:47

1 Answer 1

up vote 0 down vote accepted

OK so was way simpler than I thought in the end and didn't involve a lot, just was approaching it in completely the wrong way:

The same can be achieved like this:

     /*GETING THE USERS FIRST PUBLISHED SUBSCRIPTION?? */
$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()) {
    $first_post->the_post();

    the_time('M j, Y');

    wp_reset_postdata();

That should give you the first published subscription belonging to $IDuser but can be used for any type of post if you change the 'post_type'

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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