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.

How can i count images form NextGen Gallery, the NextGen Gallery is insite a custom field.

Custom field for NextGen Gallery is " poze "

I search for it, i found this

NextGen - Display Image Count Per Gallery

<?php 
global $wpdb; 
$images = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid = {$gallery->ID}") ); ?> 
<?php echo $images; ?>

This code it display me the 0 count of pictures...

Mode 2 wath i try

  <?php 
        global $wpdb; 
        $images = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures") ); ?> 
        <?php echo $images; ?>

This code it display me the all pictures of galery's...

Mode 3 wath i try

<?php $related_posts = get_field('poze');$count = 0;if( !empty($related_posts) ){$count = count( $related_posts ); }echo $count; ?>

This code is retriving me the number of galerry's

How can i retrive the number pof pictures atached to that gallery... Ex: 12 pictures

How can i add the custom field (poze - where ID is stored) ... anny solution woud be apreciate.

share|improve this question
    
Did you try to run the query directly in PHPMyAdmin? I suppose $gallery->ID is correct, right? –  brasofilo Jan 24 '13 at 14:31
    
hy bransofilo, i am not so good with php, i found that in search.. "SELECT COUNT(*) FROM $wpdb->nggpictures" it count me all the pictures from all the gallery's. I want to integgrate somhow the Custom Field ... the custom field is the ID of the Gallery –  Batman Jan 24 '13 at 17:16

1 Answer 1

up vote 2 down vote accepted

Assuming you actually have something in the $gallery object (hint: confirm that by print_r($gallery) in your template), then your code should work. Perhaps step back and leave the database stuff to NextGEN, just count the image IDs:

global $nggdb;
$poze = get_field('poze');
if ($poze && count($poze)) {
    $galleryID = $poze[0]['ngg_id'];
    $imageIDs = $nggdb->get_ids_from_gallery($galleryID);
    $count = count($imageIDs);
}
share|improve this answer
    
Note i use custom field to add galley Custom field : poze I tried this : <?php global $wpdb; $gallery = get_post_meta($post->ID, 'poze', true); $images = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid = {$gallery->ID}") ); ?> <?php echo ($images); ?> when i print_r it retrive me the code UP it retrive me this .. 0Array ( [0] => Array ( [ngg_id] => 14 [ngg_form] => gallery ) ) 1) when i use that code –  Batman Jan 25 '13 at 0:18
    
What does get_field('poze'); return in your code? Have you confirmed that it's a gallery ID? –  webaware Jan 25 '13 at 0:35
    
<?php echo get_field('poze'); ?> it retrive me the word Array [IMG]i49.tinypic.com/2vjy3rp.jpg Left - The custom Field, Right - Were I select the Galley( EX: Fire with Fire –  Batman Jan 25 '13 at 0:44
    
Right, you need to get the gallery ID from within that array. print_r(get_field('poze')); to see what it has in it. –  webaware Jan 25 '13 at 0:47
    
retrive me this Array ( [0] => Array ( [ngg_id] => 24 [ngg_form] => gallery ) ) ) 24 is the id of gallery –  Batman Jan 25 '13 at 0:48

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.