• Resolved parisology

    (@parisology)


    Would like to know a way to determine in PHP code if a gallery exists, and how many images it contains. Reason for this is that I have a list of hyperlinks to posts, and I want to add an icon to each link to show if there are images. Right now I am querying the database directly but this is kind of messy. I am looking in the postmeta table and the key “foogallery_attachments” but the key value is sort of cryptic. When there are no images, the key value contains “a:1” but if there are 3 images, the key value contains “a:3”, and that’s odd. Any help appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter parisology

    (@parisology)

    I had to grep the plugin source for a while to figure it out, and it all seems to be in class-foogallery.php.

    $gallery = FooGallery::get_by_id($gallery_id);
    if($gallery)
    $image_count = $gallery->attachment_count();

    Plugin Author bradvin

    (@bradvin)

    hi @parisology

    That is the way I would have suggested.

    There are quite a few useful properties and functions on the FooGallery class:

    
    $gallery->gallery_template //returns what template is being used (string)
    
    $gallery->settings //returns all the gallery settings (array)
    
    $gallery->has_attachments() //returns true if the gallery has any attachments
    
    $gallery->attachment_count() //returns number of attachments
    
    $gallery->attachments() //returns array of attachment objects (FooGalleryAttachment[])
    
    $gallery->find_usages() //returns array of posts/pages where the gallery is used (WP_Post[])
    
    • This reply was modified 4 years, 9 months ago by bradvin.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘API to query galleries for number of images?’ is closed to new replies.