guys! I have the following problem to solve - I am using Private Content plugin which divides users into categories. I need to show all posts from the category that the author is part of. I tried adding a custom query, which as tested returns the proper count of rows that are affected, but I can't get it to show the elements of the array (I have declared global $wpdb):

if (!current_user_can('administrator')) {

        //$groupcat is something like this string 'a:1:{i:0;s:2:\"23\";}';
        $groupcat = $wpdb->get_results( "SELECT `categories` FROM 7NIaM6l_pc_users WHERE `wp_user_id` = 13", ARRAY_N);
    //Here I count the results and display them in the browser's console for check, which works fine
    $ac = count($groupcat);
    echo '<script>console.log("count ' . $ac . ' ")</script>';

//This part doesn't work.
echo '<script>console.log("First element: ' . groupcat[0] . ' ")</script>';

I can't comment due to low reputation so sorry for posting this as an answer, but you are missing $ (dollar sign) near groupcat[0]

| improve this answer | |
  • I accidentally deleted it, but even with a $ it doesn't work – Simon Torak Nov 4 '19 at 13:51
  • Yes, because you can not print an array like that. Try wrapping it into json_enocde, so it woud look like json_encode( $groupcat[0] ); – Mindaugas Jakubauskas Nov 4 '19 at 14:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.