我对编码还不熟悉,但我喜欢(在虚拟服务器上)摆弄一些东西,以便在我有时间的时候升级我当前的网站。
对我来说真正有用的是发布自定义帖子的单个属性,但大多数支持似乎是显示整个帖子。
我在我的网站的某个区域有一个成员表,仅供管理员使用,我想发布他们订阅的发布日期(custom post type \'subscription\') 在表格中。
我已经有了$UserID - 应符合meta_key \'member\' 在自定义帖子中。。。
当meta_key \'member\' = the userID?
如果有人认为有帮助,我可以发布到目前为止我拥有的必要代码。。。在过去的几天里,我一直在为这件事大发雷霆,因为我尝试的所有代码都发布了不准确的日期——要么是页面的日期,要么是看似随机的传播,似乎与个人用户没有任何关联。
这张桌子是foreach结构。
编辑:添加代码。获取用户首次发布的订阅??是我遇到问题的注释位。如果你愿意,我可以解释任何函数
<?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>
抱歉,如果有点乱-我只是一个业余程序员。。。。
最合适的回答,由SO网友:Bysander 整理而成
好吧,那么最终是不是比我想象的要简单得多,也没有涉及太多,只是用了完全错误的方式:
同样可以通过以下方式实现:
/*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();
这将为您提供属于的第一个已发布订阅
$IDuser
但如果您更改
\'post_type\'