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….
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:
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'