The Pods Framework for WordPress, a specific utility that’s been around for a long time, offers a lot of functionality that can make working with advanced content types, custom settings, and so on.

Current User ID with Pods: Pods Framework

I mention this because Pods is a popular utility and there are some features available that provide some nice functionality.

Through the use of shortcodes, it’s possible to perform some powerful database queries to retrieve information to populate forms dynamically.

One use case that I see showing up in a few results is how to populate a shortcode with the current user’s ID. There’s a forum post about it here and a continued discussion about it on Stack Overflow, too.

But if you’re looking for a way to filter the content to do this without reworking some of the existing shortcodes, there’s another way to do it.

Use The Current User ID with Pods

Let’s say that you want to populate a form with the current user’s ID without a shortcode; you can do so through the use of a token and a filter.

For example, let’s say that your shortcode looks something like this:

View the code on Gist.

To filter this, as opposed to using a shortcode, you can do the following:

View the code on Gist.

This will look for a specific token in the string, replace it, and then return it with a Pods-friendly shortcode attribute to before the shortcode has been processed.

Then Pods will execute the query such that it looks something like this (assuming that the current user’s ID is 100):

View the code on Gist.

One thing I want to make clear is that I don’t necessarily recommend this over using shortcode manipulation.

Rather, use whatever best fits the situation. If it’s shortcodes, see the code linked in the intro; otherwise, perhaps the above filter works fine.


Leave a Reply