获取作者ID -WordPress,WP作业经理



我正在使用 job_listing的WP作业经理插件作为post_type

在单个作业列表页面上,我试图显示同一用户发布的所有作业列表的列表。

我无法弄清楚如何正确获取帖子作者的ID

我一直在尝试使用'author' => get_current_user_id()查询,但不是。

这仅获取当前用户的ID,这是我登录时的我,并显示我的所有列表。

我如何获得我目前正在查看的帖子的作者?

这是我当前正在尝试的内容,但它只会显示我自己的列表作为登录用户:

function my_query_args($query_args, $grid_name) {
    if ($grid_name == 'author-listings') {
        global $current_user;
        get_currentuserinfo();
        // all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
        $query_args['author'] = $current_user->ID;
    }
    return $query_args;
}
add_filter('tg_wp_query_args', 'my_query_args', 10, 2);

global $post; $author_id = $post->post_author;

如果$ post不确定,您是否真的在一个页面上,还是您有自己的魔术的设置?

要获得作者ID,请尝试https://developer.wordpress.org/reference/functions/get_the_author_meta/

要简单地显示它,请尝试https://developer.wordpress.org/reference/functions/the_author_meta/

所以您可以尝试

$query_args['author'] = $get_the_author_meta('ID');

最新更新