custer v 0.1.6 added special request for post url
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user