Pods: Pods function has no results

Created on 31 Jan 2019  ·  3Comments  ·  Source: pods-framework/pods

Describe the bug
I have a pod with name "team_member". When using the pods function, it doesn't contain any posts. This is my code and output:

$team_members = pods('team_member');
echo 'total: '. ($team_members->total()); //displays 'total: ' - no output from the function
if ( $team_members->total() > 0 ):
  while ( $team_members->fetch() ):
    echo 'hello'; //is never displayed
  endwhile;
endif;

When using WP_Query I do get the expected output:

$args = (array('post_type' => 'team_member'));
$team_members = new WP_Query($args);
while ($team_members->have_posts()):
  $team_members->the_post();
  the_title(); //the title of each pod post is displayed
endwhile;

Why does the latter work, and the first doesn't?

Support

Most helpful comment

It did, cheers!

All 3 comments

You've opened the object, but you didn't give it any parameters, so it's basically just an object with no pointer at that point (like opening the WP_Query without any $args) . At a minimum, you want to set $params = (array('limit' => '-1')); and call the first line as $team_members = pods('team_member',$params);

https://pods.io/docs/code/pods/
https://pods.io/docs/code/pods/find/ << also very useful for passing all the query type parameters.

Did that work @jnaklaas ?

It did, cheers!

Was this page helpful?
0 / 5 - 0 ratings