stefanplc
stefanplc

Reputation: 439

Wordpress PODs Get the ID

I'm using the following code to display posts from one of my PODs. This code is on a custom single-custom.php page and it's used to display "additional items".

<?php
$rider_video_loop= new Pod('rider_video');
$rider_video_loop->findRecords('RAND()', 12);       
$rider_video_total = $rider_video_loop->getTotalRows();

if( $rider_video_total>0 ) :
while ( $rider_video_loop->fetchRecord() ) :

$thumbnail_description = $rider_video_loop->get_field('video_thumbnail_description');
echo $thumbnail_description;
$video_permalink = $rider_video_loop->get_field('permalink'); 
echo $video_permalink

endwhile; endif; ?>

The code is very basic and simple and it works really well. It accesses the POD "rider_video" and it randomly displays 12 of my posts. What I'm trying to do and I just can't seem to figure out how is to also echo the post ID for each of these entries. I've tried using get_field('id'); or get_field('post_id'); or get_the_ID(); and all that these do is get the ID of the current post page instead of the ID of these 12 entries. Can someone please help?

Thank you very much in advance!

Upvotes: 0

Views: 3264

Answers (1)

Clint Hagen
Clint Hagen

Reputation: 36

Edited: the original code only works when only one row is returned by find(). Here's what you need to do to get the ids for multiple rows:

I had this same issue and here's what I came up with:

$rider_video_loop->find('RAND()', 12);
$counter = 0;
while ( $rider_video_loop->fetchRecord() ) {
    $data = $rider_video_loop->data;
    $id = $data->data[$counter]->ID;
    $counter++;
}

The $id variable then contains the post ID.

Upvotes: 2

Related Questions