Php 如果文章不超过一个月,则显示每个作者的最新文章

Php 如果文章不超过一个月,则显示每个作者的最新文章,php,wordpress,post,title,author,Php,Wordpress,Post,Title,Author,我在网站上有一个作者列表(Wordpress),它出现在每个页面上,所以这个列表存在于循环之外 我设法用每个作者的名字展示他们的图片,但我想得到他们最新的文章标题,链接到这篇文章。文章标题应仅在文章不超过一个月时显示 任何帮助都将不胜感激 谢谢 <?php global $wpdb; $query = "SELECT ID, user_nicename from $wpdb->users WHERE ID != '1' ORDER BY 'ASC'

我在网站上有一个作者列表(Wordpress),它出现在每个页面上,所以这个列表存在于循环之外

我设法用每个作者的名字展示他们的图片,但我想得到他们最新的文章标题,链接到这篇文章。文章标题应仅在文章不超过一个月时显示

任何帮助都将不胜感激

谢谢

<?php

        global $wpdb;
        $query = "SELECT ID, user_nicename from $wpdb->users WHERE ID != '1' ORDER BY 'ASC' LIMIT 20";
        $author_ids = $wpdb->get_results($query);

        foreach($author_ids as $author) :

            // Get user data
            $curauth = get_userdata($author->ID);

            // Get link to author page
            $user_link = get_author_posts_url($curauth->ID);
            $post_link = get_permalink($curauth->ID);


            // Set default avatar (values = default, wavatar, identicon, monsterid)
            $main_profile = get_the_author_meta('mainProfile', $curauth->ID);
            $hover_profile = get_the_author_meta('hoverProfile', $curauth->ID);
            $award_profile = get_the_author_meta('awardProfile', $curauth->ID);

    ?>
您可以使用为自己创建一个新循环。自3.7版以来,它接受一个很酷的
date\u查询
参数。未经测试,但应该有效

编辑:

$args =  array(
    'showposts' => 1,
    'orderby' => 'date',
    'date_query' => array(
        array(
            'after' => array(
                'year'  => date( "Y" ),
                'month' => date( "m", strtotime( "-1 Months" ) ),
                'day'   => date( "t", strtotime( "-1 Months" ) ),
            ),
            'inclusive' => true,
        )
) );
$query = new WP_Query( $args );
然后你可以运行一个常规循环

// run the loop with $query
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
        echo 'Latest post: ' . get_the_title();
    }
} else {
    // no posts
}

你好,阿维斯特,谢谢。我试过你的答案,但是页面根本没有加载。我从上面删除了我的代码,只是为了确保它不会干扰,但仍然没有。我还注意到您编写了“$theu query”,而不是“$query”。我不确定它应该是哪一个,但无论如何它都不起作用。@wind\u kind,我的错,我已经编辑了查询并更改了$args。它似乎对我有用,看看这是否是你想要的结果