Moker
V2EX  ›  WordPress

WORDPRESS 如何获取特定用户的所有文章

  •  
  •   Moker · Dec 9, 2014 · 5152 views
    This topic created in 4350 days ago, the information mentioned may be changed or developed.
    通过QUERY_POST并没有相应的参数用来获取相应的数据
    后来想到用SQL的方式 但这样无法获取文章链接
    网上搜了居然没搜到相关教程 还是因为自己搜索的方式不对
    <?php $post = $wpdb->get_results("SELECT post_date,post_title FROM $wpdb->posts where post_author=".$_GET['usid']);
    foreach ($post as $post) {
    echo '<article class="excerpt excerpt-one" ><a href="'.the_permalink().'">'.$post->post_title.'<span class="text-muted time" style="float:right">'.$post->post_date.'</a></span></article>';
    }
    ?>
    其中usid为URL传过来的参数 用来识别用户特定ID
    4 replies  •  2014-12-09 12:40:22 +08:00
    kmvan
    kmvan
    Dec 9, 2014 via Android❤️1
    1
    new wp_query() 自己看官檔
    kungfuchicken
    kungfuchicken
    Dec 9, 2014❤️1
    2
    $query = new WP_Query( 'author=1' );
    $query = new WP_Query( 'author_name=rami' );
    kungfuchicken
    kungfuchicken
    Dec 9, 2014
    3
    玩wordpress一定要学WP_Query对象
    Moker
    Moker
    OP
    Dec 9, 2014
    4
    @kmvan
    @kungfuchicken 谢谢 已解决发现 query_post自带有author参数....以前居然没看到
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1014 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:49 · PVG 02:49 · LAX 10:49 · JFK 13:49
    ♥ Do have faith in what you're doing.