0

I have a very weird issue with wpdb which is freaking me out. My database has the following data:

INSERT INTO `wp_clb_likes` (`id`, `post_id`, `user_ip`, `time`)
VALUES
    (5,11511,'::1','2015-01-25 09:23:26'),
    (6,11511,'::1','2015-01-25 09:23:34'),
    (7,11511,'::1','2015-01-25 09:24:07'),
    (8,11511,'::1','2015-01-25 09:24:44'),
    (9,11511,'::1','2015-01-25 09:28:53'),
    (10,11511,'::1','2015-01-25 09:29:23'),
    (11,11511,'::1','2015-01-25 09:31:06'),
    (12,11511,'::1','2015-01-25 09:31:30'),
    (13,11172,'::1','2015-01-25 09:43:10'),
    (14,11511,'::1','2015-01-25 20:23:31'),
    (15,11315,'::1','2015-01-25 20:32:01'),
    (16,11025,'::1','2015-01-25 20:32:59');

In WP I have the query:

        public static function getAllObjects() {
            global $wpdb;
            global $clb_table;
        $sql = $wpdb->get_results("SELECT COUNT(*) as likes, post_id from $clb_table GROUP BY post_id ORDER BY likes DESC", OBJECT_K);
    return $sql;
}

My var_dump on the WP fronted shows this:

array(2) { [9]=> object(stdClass)#4818 (2) { ["likes"]=> string(1) "9" ["post_id"]=> string(5) "11511" } [1]=> object(stdClass)#4817 (2) { ["likes"]=> string(1) "1" ["post_id"]=> string(5) "11172" } }

Why I am only seeing post_id 11511 and 11172 and not 11315 and 11025 as well?

Does anybody know the reason? Thanks!

  • I solved it by myself. Its because of the OBJECT_K in the query. If i leave this to OBJECT, everything is fine. Does anybody know why OBJECT_K is not working here? – Torben Jan 29 '15 at 10:16
  • You should post that as an update to your question if you need any clearity on that issue :-) – Pieter Goosen Jan 29 '15 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.