WordPress PODS display content from a post

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:

Read More
  • 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?

Related posts

Leave a Reply

2 comments

  1. pod-type-slug should be replaced by the slug of your pod type. The pod-slug is the slug of the specific pod content you created:

    //Pods->display has been deprecated since Pods version 2.0 with no alternative available according to a warning when trying to use this function:
    $pod = pods('pod-type-slug', "pod-slug");
    
    $pod->display('title')
    $pod->display('post_content')
    

    etc.

    You can also use the default WordPress functionality:

    $pod = pods('pod-type-slug', "pod-slug");
    
    $row = $pod->row();
    
    //print the pod content:
    echo $row->post_content;
    
    get_the_post_thumbnail($row['ID']);
    
  2. 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 called podutils and create a php file called PodUtils.php.

    Copy/paste this class into that file:

    <?php 
    //Class to get WordPress Pod data:
    class PodUtils {
    
        //get WordPress Pod Object: 
        public static function GetPodObject($podType, $podSlug) {
            //for use with Pods WP Plugin (https://pods.io/):
            if(function_exists("pods")) {
                $pod = pods($podType, $podSlug)->row();
                return $pod;
            } else {
                return false;
            }       
        }
    
        //get the content from a WordPress Pod: 
        public static function GetPodContent($podType, $podSlug) {
            $pod = PodUtils::GetPodObject($podType, $podSlug);      
            if($pod !== false) {
                return $pod["post_content"];
            } else {
                return false;
            }
        }
    
        //get a custom field from a WordPress Pod:  
        public static function GetPodMeta($podType, $podSlug, $metaName, $isSingle = true) {
            $pod = PodUtils::GetPodObject($podType, $podSlug);
            if($pod !== false) {
                return get_post_meta($pod["ID"], $metaName, $isSingle);
            } else {
                return false;
            }
        }
    
    }
    

    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.