如何获取作者的定制帖子?

时间:2017-07-26 作者:sanjay yadav

这是代码,基本上我想通过博文作者获取,但无法解决此问题,对此有任何帮助。

<?php 
 global $post;
                  $author = get_the_author();
                    $args = array(
                        \'author\'  =>$user_ID,
                        \'posts_per_page\' => $per_page,
                         \'author\'=> $author,
                        \'post_type\' => \'ultimate-auction\',
                        //\'auction-status\' => \'expired\',
                        \'post_status\' => \'publish\',
                        \'offset\' => $pagination,
                        \'orderby\' => \'meta_value\',
                        \'meta_key\' => \'wdm_listing_ends\',
                        \'order\' => \'DESC\',
                        );  
    $author_posts = new WP_Query( $args );
    if( $author_posts->have_posts() ) {
        while( $author_posts->have_posts()) {
            $author_posts->the_post();
            ?>
            <?php the_content();?></div>
    <?php
            // you should have access to any of the tags you normally
            // can use in The Loop
        }
        wp_reset_postdata();
    }
    ?>

2 个回复
SO网友:Johansson

您正在使用\'author\' => ... 在代码中输入两次。

要获取作者的ID,您应该使用get_the_author_meta(\'ID\') 相反因此,请删除第二个author参数,并在代码中使用它:

  $author = get_the_author_meta(\'ID\');
    $args = array(
        \'posts_per_page\' => $per_page,
        \'author\'=> $author,
        \'post_type\' => \'ultimate-auction\',
        //\'auction-status\' => \'expired\',
        \'post_status\' => \'publish\',
        \'offset\' => $pagination,
        \'orderby\' => \'meta_value\',
        \'meta_key\' => \'wdm_listing_ends\',
        \'order\' => \'DESC\',
    );
顺便说一下,全球$post 它本身包含帖子作者的ID,您可以使用$post->post_author;.

如果要使用作者的姓名,可以使用\'author_name\' => ... 连同get_the_author_meta(\'nicename\').

看看author parameters 属于WP_Query 详情请参阅WordPress codex。

SO网友:Dharmishtha Patel
$args = array(
    \'author\'        =>  $current_user->ID,
    \'orderby\'       =>  \'post_date\',
    \'order\'         =>  \'ASC\',
    \'posts_per_page\' => 1
    ); 
结束

相关推荐

Get Parent Theme Author Name

我想获取父主题的作者名称。我可以使用wp\\u get\\u theme()获取主题名称,以获取当前(子)主题的主题对象。从这里我可以得到父主题名称。接下来,我想我需要获得父主题的对象,但不确定如何最好地实现这一点。以下是我目前的代码:$style_parent_theme = wp_get_theme(); $style_parent_theme_dir = $style_parent_theme->get( \'Template\' ); $style_parent_theme_