wordpress get_post_meta使用全局$ user_ID

时间:2013-05-05 18:52:03

标签: php wordpress wordpress-plugin

我想更改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; ?>

3 个答案:

答案 0 :(得分: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();
?>

答案 1 :(得分:0)

您可以使用global $current_userget_currentuserinfo()来填充query_posts()参数的用户ID。

<?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; ?>

答案 2 :(得分:-2)

在Query()函数中,author参数可用。 你可能会发现它here

相关问题