2013-05-05 90 views
0

我想更改wordpress脚本。我想要使​​用get_post_meta获得所有元帖子。但如何从$user_ID开始。我的意思是我有用户ID,没有更多,我想要他的元帖子,类似的输出作为get_post_meta()

例如这个例子接近我所需要的,但它没有找到任何帖子,找到0帖子。

<?php query_posts('author=32'); ?> 
<?php if(have_posts()) : while(have_posts()) : the_post(); ?> 
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
<?php endwhile; endif; ?> 

回答

0

您可以使用global $current_userget_currentuserinfo()到功能填充用户ID为query_posts()参数。

<?php 
// get the current user and populate 
global $current_user; 
get_currentuserinfo(); 

// use the current user ID as the author and query for posts 
$args = array('author' => $current_user->ID); 
query_posts($args); 
?> 
<?php if (have_posts()): while(have_posts()): the_post(); ?> 
    <?php the_title(); ?> 
<?php endwhile; endif; ?> 
0

试试这个

<?php 
// The Query 
query_posts('author=<id>'); 
// The Loop 
if (have_posts()) : while (have_posts()) : the_post(); 
"<a href="the_permalink();">"the_title();"</a>"; 
endwhile; 
// Reset Query 
wp_reset_query(); 
?> 
-2

在查询()函数author参数可用。 你会发现它here