Search code examples
wordpressrating

Wordpress - GD Star Rating - Set Rating after wp_insert_post


is it possbile to rate the new post (with admin account) after this?

$post_id = wp_insert_post( $my_post, $wp_error );

Solution

  • According to this post of the Wordpress support forum, what you should do is something like this:

    function set_rating($post_id, $vote) {  // $vote = 0..10
      $admin = get_user_by('login', 'admin');
      if ($admin !== false) {
        $ip = $_SERVER['SERVER_ADDR'];
        $ua = $_SERVER['HTTP_USER_AGENT'];
        gdsrBlgDB::save_vote($post_id, $admin->ID, $ip, $ua, $vote);
      }
      return $admin;
    }