[英]Wordpress/ACF: Posts related to author
我需要個人資料頁面上wp-admin中的列表,其中列出了所有用戶的帖子。 不只是post_type post
,也與author
與當前用戶ID。
我已經將Relationshop設置為post_type,但是是否可以進行其他某種“元查詢”,所以我只能選擇顯示當前用戶的帖子嗎?
答案是創建一個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);
並將其添加到functions.php
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.