ansonphong / postworld

Wordpress Theme Development Framework
GNU General Public License v2.0
7 stars 0 forks source link

Post Points Functions #75

Closed ansonphong closed 10 years ago

ansonphong commented 10 years ago

Hi Haidy, I'm working with the post points functions and I'm finding they're not doing what is expected. Here are some instances :


cache_user_posts_points() Has no method

You can see by the function, that the function is simply acting as an alias of calculate_user_posts_points() (which is good), although it's not doing it's work by caching the actual points or writing anything to the table.

function cache_user_posts_points ( $user_id ){
  return calculate_user_posts_points($user_id);
}

cache_user_posts_points() Returning wrong value

For instance, when running : cache_user_posts_points(), it seems to generally work well, although there are two major issues:

Code:

echo json_encode( cache_user_posts_points ( $displayed_user_id ) );

Result:

{"total":96,"0":{"post_type":{"post":"0","link":"0","blog":"3","event":0,"":"81","feature":"12"}}}
  1. The result isn't being written into the wp_postworld_user_meta table
  2. There is an unknown value "":"81" which is adding 81 points to the user from an unknown post type (these points don't seem to be anywhere in the points table)

Please help me solve these issues so that all the good work you've invested in these functions can be implemented.

ansonphong commented 10 years ago

I found another vital issue with the way the points are working, whereby the post types seem to be hard-coded into two of the functions.

Post Types Hard-coded

In postworld_points.php you can see on lines 127 and 248 there are custom post_types which are being hard coded into default results. (I changed event to 'tribe_events')

array("post_type"=> array ("post"=> 0,"link" =>0,"blog" =>0, "tribe_events" => 0));

We need to use get_post_types to get the actual current registered post_types: http://codex.wordpress.org/Function_Reference/get_post_types

Here is a post type query which should work:

$args = array(
   'public'   => true,
   '_builtin' => false
);

$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'

$post_types = get_post_types( $args, $output, $operator ); 
ansonphong commented 10 years ago

BTW - the 'Share Karma' is working very well - I'm happy about that.

ansonphong commented 10 years ago

OK this thread is closed - I can fix the hard-coded post types.