简体   繁体   English

Wordpress / ACF:与作者相关的帖子

[英]Wordpress/ACF: Posts related to author

I need a list, in wp-admin, on the profile page, which lists all the users posts. 我需要个人资料页面上wp-admin中的列表,其中列出了所有用户的帖子。 Not just post_type post , but also with author with the current user ID. 不只是post_type post ,也与author与当前用户ID。

I've set the relationshop to the post_type, but isn't it possible to make another "meta query" of some sort, so I can chose only to show the current users posts? 我已经将Relationshop设置为post_type,但是是否可以进行其他某种“元查询”,所以我只能选择显示当前用户的帖子吗?

The answer is to create an ACF relationshop query . 答案是创建一个ACF Relationshop查询

function profile_relationship_query( $args, $field, $post_id ) {
    $post_type = $args["post_type"][0];

    $args = array(
        'numberposts' => 10,
        'post_type'   => $post_type,
        'meta_query'  => array (
            array (
                'key'     => 'authors',
                'value'   => '"' . $post_id . '"',
                'compare' => 'LIKE'
            )
        )
    );

    return $args;
}
add_filter('acf/fields/relationship/query/name=profile_articles', 'profile_relationship_query', 10, 3);

And add it to functions.php . 并将其添加到functions.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM