1

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!

1
  • Solved it myself. Because of the OBJECT_K setting in the get_results() the function does not list all items of the database...I replaced OBJECT_K with the default OBJECT and it works. Commented Jan 29, 2015 at 10:21

1 Answer 1

1

Solved it myself. Because of the OBJECT_K setting in the get_results() the function does not list all items of the database...I replaced OBJECT_K with the default OBJECT and it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.