custer v 0.1.6 added special request for post url

This commit is contained in:
asus
2024-03-25 21:42:33 +01:00
parent 44a5d93f77
commit 90fb5bc0b6
4 changed files with 45 additions and 5 deletions

View File

@@ -49,6 +49,17 @@ function format_user_info($query, &$current_user, $user_id) {
}
/*
* if is special query __user_post__
* return author page url
*
*/
if ($query === '__user_post__') {
$output = \CUSTER\find_user_post_url($user_id);
return \CUSTER\return_result($output);
}
/*
* check if it's an acf field
*
@@ -104,4 +115,31 @@ function format_user_info($query, &$current_user, $user_id) {
/*
* find the posts of the user and return the first one
*
*/
function find_user_post_url($user_id) {
$user_post_url = '';
$args = array(
'post_type' => 'post',
'author' => $user_id,
'posts_per_page' => 1,
);
$posts = get_posts($args);
if (empty($posts)) {
$user_post_url = '';
}
else {
$query = reset($posts);
$user_post_url = get_permalink($query->ID);
}
return $user_post_url;
}
?>