• Resolved Stefancom

    (@stefancom)


    Hi!

    On my website, I want several types of data from my Pods counted and those numbers displayed. For example, I eventually successfully managed to display the total count of posts of one Pod; or the total count of posts of a Pod, BUT filtered by one specific relationship field.

    Now as a third thing, I would like to count the number of images associated with one Pods post. But my existing codes do not work.

    One code, based on one that I have already for other counting results, would be:

    <?php
    	$params = array(
    		'where' => 'images.id=' . get_the_id(),
    		'limit' => -1
    	);
    	$pod = pods ('work', $params);
    	echo '<b>Photos</b> (' . $pod->total () . ')<br/>';	
    ?>

    So, it is about “images” in the Pod “work”. But this does not really work, does it? There is no “images.id”, anyways.

    There are suggestions concerning WordPress flying around online, such as:

    <?php while ( $the_query->have_posts() ) : $the_query->the_post();
      $attachments = get_children( array( 'post_parent' => $post->ID, 'post_mime_type' => 'image' ) );
    
        $count = count( $attachments );
        $specific = array();
        $i = 1;
              foreach ( $attachments as $attachment ) {
             $specific[$attachment->ID] = $i;
        ++$i;
        }  ?> <a href="#"><?php echo $count; ?></a>
          <?php endwhile; ?>

    And:

    $count = count( get_attached_media( 'image', $post->ID ) );

    Does any of this lead somewhere useful? Is there a way to translate that into usable Pods code?

    Best,

    Stefan

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Count Media in Images Field’ is closed to new replies.