简体   繁体   中英

wordpress get_post_meta using global $user_ID

I want to change a wordpress script. I want to get all meta posts using get_post_meta . But how to do that with starting from $user_ID . I mean that I have user ID and nothing more, and I want to get his meta posts, similar output as of get_post_meta() .

For example this example is close to what i need, but it not finding any posts, 0 posts are found.

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

Try this

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

You can use the global $current_user and get_currentuserinfo() to function populate the user ID for the query_posts() arguments.

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

In Query() function author parameter is available. you may find it here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM