0

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..

1

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);
?>

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.