简体   繁体   中英

Wordpress/ACF: Posts related to author

I need a list, in wp-admin, on the profile page, which lists all the users posts. Not just post_type post , but also with author with the current user 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?

The answer is to create an ACF relationshop query .

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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