After further investigation it appears that pulling from the postmeta table is whats causing the issue, the same code can pull from any other table and using wp_postmeta instead of $wpdb->postmeta causes the same issue. The interesting thing is that if I make the query invalid by changing it to postmeta the query of course fails but the page loads.
Works perfectly fine for me, some simple test code.
$querystr = "SELECT * FROM $wpdb->postmeta pm JOIN $wpdb->posts p ON p.ID = pm.post_id";
$myPosts = $wpdb->get_results($querystr, OBJECT);
print 'hello world!';
var_dump( $myPosts );
I see “hello world” and the var_dump()
result just fine.
What does this line output for you?
print $querystr; // This line prints
It would be my guess/assumption you’re not forming that query string correctly.
NOTE: You don’t need those backticks around the table names.
Looks like its the WP site I’m testing on, not sure its the theme or something else but with a base WP install everything works so something on my end.
Thanks!
EDIT: Nevermind, i see what you’re doing, checked the pastebin again, that’s clearly a shortcode function.
NOTE: Your get_results call doesn’t need to declare the return type(ie. object), object is default.
A bit stumped as to the cause of the problem though.
Does the query work if you remove the query string and perform a generic query like my sample one above?
Nope even very basic queries fail, however if i comment the get_results line everything loads fine, very strange issue.
Maybe you’re not getting access to $wpdb
when you should be..
What does a var_dump()
or print_r()
on $wpdb
produce?
It actually dumps out a ton of info from that variable leading me to believe the variable is valid but still doesn’t dies at the same spot.
Well that’s odd i must admit, can’t think why you’d have the problem with get_results
.
Is the site you used for testing where the code works also running the same version of WordPress? (3.0.3 is it?)..
Sorry looks like I posted the wrong version, the test site is 3.0.3 and the site its failing on is 3.0.4