I have tried multiple solutions that I have found around and none seem to be working. Can anyone give me any help? I want the result to return the ID's ($user) and currently it returns [object Object] with the code below. $users gives me all the sites user ID's and $pageview gets the number of times the page has been visited. If I change the return statement to $test I get all the values from $pageview correclty as they should be. The need for adding the key 'count' as $pageview is so that I can sort the array by the value of pageview in order to order the values based on the most popular page. I know this isn't the most efficient way to do this and using a proper analytics system would be better but for this task I need a method like this.
if($args == 'Popular'){ $users = get_all_user_ids(''); foreach($users as $user) { $pageview = get_user_meta($user, 'page_visits', true); $test[] = $pageview; if ($pageview != 0) { $popularid[$pageview]['count'] = $user; } else { continue; } rsort($popularid); } return $popularid; } The output is being encoded with json_encode after it has gone through this if statement and is then output onto the page in a JS function using document.getElementById("cm-output").innerHtml.
Thanks in advance.
$pageviews = $pageview + $user;