Moker
V2EX  ›  WordPress

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

  •  
  •   Moker · Dec 9, 2014 · 4851 views
    This topic created in 4179 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
        1
    kmvan  
       Dec 9, 2014 via Android   ❤️ 1
    new wp_query() 自己看官檔
    kungfuchicken
        2
    kungfuchicken  
       Dec 9, 2014   ❤️ 1
    $query = new WP_Query( 'author=1' );
    $query = new WP_Query( 'author_name=rami' );
    kungfuchicken
        3
    kungfuchicken  
       Dec 9, 2014
    玩wordpress一定要学WP_Query对象
    Moker
        4
    Moker  
    OP
       Dec 9, 2014
    @kmvan
    @kungfuchicken 谢谢 已解决发现 query_post自带有author参数....以前居然没看到
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1466 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:54 · PVG 00:54 · LAX 09:54 · JFK 12:54
    ♥ Do have faith in what you're doing.