0

apologies that this is very basic stuff but would really appreciate some help. I am trying to query a table in my Wordpress database by adding the following to my child theme's functions.php

$myresults = $wpdb->get_results("SELECT id FROM wp_my_table WHERE user_id=1");

I am trying to view the results of the query by adding

<?php
    var_dump($myresults);
?>

to one of the pages on my website, but it just displays 'NULL'. I have checked using phpMyAdmin and wp_my_table definitely exists, and contains entries where user_id=1. Any ideas?

2 Answers 2

1

not get_results!!! query

$wpdb->get_results(...

to

$wpdb->query(...
Sign up to request clarification or add additional context in comments.

4 Comments

Not working unfortunately - the var_dump still displays 'NULL'
Sorry but I'm not sure what that means!
Send the part of the code where you connect to the database
I thought I didn't have to open a separate DB connection with $wpdb? The rest of the website works great so the database connection must be fine I guess? I have tried adding global $wpdb; before my code but that doesn't work either
0

Sorry, I missed something obvious - the scope of the $myresults variable didn't extend to the page I was performing the var_dump on!

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.