Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pods function has no results #5283

Closed
jnaklaas opened this issue Jan 31, 2019 · 3 comments
Closed

Pods function has no results #5283

jnaklaas opened this issue Jan 31, 2019 · 3 comments
Assignees
Milestone

Comments

@jnaklaas
Copy link

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?

@jimtrue
Copy link
Contributor

jimtrue commented Jan 31, 2019

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.

@jimtrue
Copy link
Contributor

jimtrue commented Jan 31, 2019

Did that work @jnaklaas ?

@jnaklaas
Copy link
Author

It did, cheers!

@jimtrue jimtrue self-assigned this Jan 31, 2019
@sc0ttkclark sc0ttkclark added this to the Pods 2.7.13 milestone Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants