Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I tried a few echo commands, and they return properly.

Breaking Statement

<?php 
$gallery_ids = $wpdb->get_results(
"SELECT gid FROM ".$wpdb->prefix."ngg_gallery ORDER BY gid ASC", ARRAY_A);
?>

This causes anything after this statement not to show up, consequentially breaking the page.

If I do things like this :

<?php
$custom_query = new WP_Query( 'posts_per_page=3&cat=1' );
if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>

<p id="title"><?php the_title(); ?></p>
<p id="small-date">Posted on: <?php the_time('F j, Y') ?></p>
<?php the_excerpt(); ?>
<hr />

It works fine. So I know it can take complicated PHP statements.

I'm curious why my previous statement would break..

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Make sure you reference the global $wpdb variable first, otherwise PHP doesn't know what $wpdb is or whether or not it has a get_results() method or a prefix property.

So just add global $wpdb; to fix it:

<?php 
global $wpdb;
$gallery_ids = $wpdb->get_results(
"SELECT gid FROM ".$wpdb->prefix."ngg_gallery ORDER BY gid ASC", ARRAY_A);
?>
share|improve this answer
    
Thanks EAMann!! –  Trip Nov 21 '11 at 2:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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