简体   繁体   English

按用户显示帖子

[英]Show posts by user

So, here is my php to show posts for wordpress: 因此,这是我的php显示wordpress的帖子:

<div class="rfp_hide" id="rhm_profile_item">
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array( 
        'post_type' => 'product',
        'paged' => $paged,
        'posts_per_page' => 20,
        'orderby' => 'date',        
        'order' => 'DESC'
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); 
    global $product, $post, $paged; 
?>
<div class="rhm_post_container">
      Posts go here
</div>

    <?php endwhile; ?>
    <?php wp_reset_query(); ?>  

</div>

It shows all the posts regardless of who posted. 它显示所有帖子,无论谁发布。

Each post has its href as following: 每个帖子的href如下:

<a class="royal_author_link" href="<?php echo $userpro->permalink( $post->post_author ); ?>">

On the post author page, the permalink has following structure : 在帖子作者页面上,永久链接具有以下结构:

example.com/profile/someone.

Now, how can I modify it so that when I am in a specific user page, it only shows the posts by that user only? 现在,如何修改它,这样当我进入特定用户页面时,它仅显示该用户的帖子?

Did you use a custom plugin to create the profile page? 您是否使用自定义插件来创建个人资料页面? In case you have access to the user ID related to the page, you can extend the query argument by the attribute "author" , like so: 如果您有权访问与页面相关的用户ID,则可以通过属性“ author”扩展查询参数,如下所示:

$args = array( 
    'author' => $yourUserID
    'post_type' => 'product',
    'paged' => $paged,
    'posts_per_page' => 20,
    'orderby' => 'date',        
    'order' => 'DESC'
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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