WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Output Total Records For Shortcode (9 posts)

  1. listingwarebob
    Member
    Posted 8 months ago #

    I'm using a PODS shortcode to fetch records. How do I output the query record count / total rows found?

    http://wordpress.org/plugins/pods/

  2. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 8 months ago #

    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.

  3. listingwarebob
    Member
    Posted 8 months ago #

    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?

  4. listingwarebob
    Member
    Posted 8 months ago #

    Could it maybe be something like:

    [pods]{@total}]/pods]

  5. listingwarebob
    Member
    Posted 8 months ago #

    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.

  6. Josh Pollock
    Member
    Plugin Author

    Posted 8 months ago #

    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.

  7. listingwarebob
    Member
    Posted 8 months ago #

    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?

  8. Josh Pollock
    Member
    Plugin Author

    Posted 8 months ago #

    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.

  9. listingwarebob
    Member
    Posted 8 months ago #

    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? :)

Reply

You must log in to post.

About this Plugin

About this Topic