There is a wordpress website with the Pods plugin installed - Custom Content Types and Fields for displaying user posts. I create a new type with the name test , in which I add a text field test_text and create an instance of this type from the side menu. Now I have a question: how to display instances of these types with a field on the template page

 <div><?php $text = pods('test'); echo $text->field('test_text');?></div> 

$text object receives (see through var_dump), but the field does not display - why? I attach screenshots: photo 1 photo 2 photo 3 photo 4 then inside the index.php file I prescribe:

 <span><?php echo get_post_meta(get_the_ID(), 'test_text', true) ?></span> 

the span empty ..

    2 answers 2

    Try

    <?php echo get_post_meta(get_the_ID(), 'test_text', true) ?>

    Here is how it looked in the project:

      <div class="catalog wrap" data-block="2"> <h2><?php echo $brief_catalogue; ?></h2> <ul> <?php $currentPage = $post ?> <?php $smesi = new WP_Query([ 'post_type' => 'smesi', 'post_status' => 'publish', 'posts_per_page'=> -1, 'order' => 'ASC' ]); ?> <?php $i = 1 ?> <?php while($smesi->have_posts()): ?> <?php $smesi->the_post(); ?> <li> <a href="<?php the_permalink(get_the_ID())?>" title="<?php the_title() ?>" ?> <div class="product-item"> <div class="img"> <?php the_post_thumbnail('full'); ?> </div> <div class="info"> <h3><?php echo html_entity_decode(get_post_meta(get_the_ID(), 'info_name', true)) ?></h3> <p><?php echo get_post_meta(get_the_ID(), 'info_description', true) ?></p> <div class="button">Подробнее</div> <div class="price"><?php echo get_post_meta(get_the_ID(), 'info_price', true) ?></div> </div> </div> </a> </li> <?php endwhile ?> <?php wp_reset_query() ?> <?php $post = $currentPage ?> </ul> </div> 
    • and where to get_the_ID ()? expectedly nothing output - Vasya
    • one
      everything worked for me, get_the_ID () will pull itself up from your page. I set up Pods specifically for this, created the same CPT and displayed its contents - eugene_v
    • let's look - specifically in the description added screenshots - do you? - Vasya
    • one
      And where does index.php, if you register a custom-post-type? If I'm not mistaken in this case, you need to make a conclusion of the posts in the loop and output this code there. If now I remember in what project I did it, I will show an example - eugene_v
    • one
      Here on this test site, the text Some text description is displayed thanks to this code <?php echo get_post_meta(get_the_ID(), 'test_text', true) ?> Specified in the single.php template. In response to your question, I added the code that was displayed in the project in index.php - eugene_v

    The get_theID() function returns the ID of the current object in the main or user loop. In the example from @eugene_v, the current object (post) is set by calling $smesi->the_post(); . You need to take an ID from a pods instance, namely something like $text->id; (I don’t know for sure; see the source)