I’ve recently started using WordPress PODS plugin and I’m having a little trouble displaying some basic content. I can display custom fields content just fine using the following:
<?php
$field_name = get_post_meta( get_the_ID(), âmy_field_nameâ, true );
echo $field_name; ?>
However I can’t get basic stuff such as the following:
- title (which in regular posts itâs just
the_title();
) - content (which in regular posts itâs just
the_content();
) - featured image
Can someone please help me figure out how to pull the title, content and featured image from a POD?
pod-type-slug
should be replaced by the slug of your pod type. Thepod-slug
is the slug of the specific pod content you created:etc.
You can also use the default WordPress functionality:
After a frustrating hour of Googling and looking through their examples, there didn’t seem to be a single source of how to get a Pod’s content or custom field. The answer above helped me a bit, but wasn’t well explained.
In your
wp-content/plugins
folder, create a new folder calledpodutils
and create a php file calledPodUtils.php
.Copy/paste this class into that file:
To use the class with static methods, do so as follows:
Include the PodUtils.php file in the php file you want to use it:
require_once ABSPATH . 'wp-content/plugins/podutils/PodUtils.php';
Get content:
$strPodContent = PodUtils::GetPodContent('pod-type', 'pod-item-slug');
Get meta (custom field you added to a pod type):
$strPodMeta = PodUtils::GetPodMeta('pod-type', 'pod-item-slug', 'custom-meta-name');
This can easily be changed to an object that you instantiate with public functions, or a plugin of its own.