Support » Plugin: Pods - Custom Content Types and Fields » Output Total Records For Shortcode

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Try http://pods.io/docs/code/pods/total/ for how many were pulled onto the page (pagination taken into account, it would be 10, if you had the limit set to 10 and there were 12 records, on the first page).

    And then there’s http://pods.io/docs/code/pods/total-found/ which will return how many total were found, regardless of pagination.

    I did see the total and total_found functions, but was trying understand exactly how they could be used with shortcodes. Can you provide an example of that?

    Could it maybe be something like:

    [pods]{@total}]/pods]

    FYI, earlier on the page I have a one-line shortcode like this:

    [pods name=”document” template=”document_list”]

    What I want is to be able to display the total or total_found at the bottom of that page after (or ideally, both before and after) the one-line PODS shortcode.

    Plugin Contributor Josh Pollock

    (@shelob9)

    In a Pods template you can open php tags and use any Pods or WordPress functions you need. The current Pods object is stored in $obj, so, for example <?php echo $obj->total; ?> would output the total number of records returned.

    I had tried something along those lines, but it didn’t work. Please note, I had said above that I’m using a one-line shortcode. Is there a way I can output that total value using the shortcode implementation?

    Plugin Contributor Josh Pollock

    (@shelob9)

    There is no way to get the value of pods::total() directly in the Pods shortcode. You example [pods]{@total}[/pods] would return the the value of a field called total. You could write your own shortcode plugin that called pods::total() inside of it. I think that using the template, which works for me, would be easier.

    It wasn’t the most elegant output, but I went ahead and output the total() value as a hidden element in the pods template. I then could use a little jQuery to replicate it anywhere I want on the page. What matters is getting the result you want, right? 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Output Total Records For Shortcode’ is closed to new replies.