将自定义字段添加到 Wordpress

Add custom filed to Wordpress

我正在尝试将自定义字段添加到我的 Wordpress 页面,但它不起作用。当我设置它的值时,HTML 上没有任何反应。

我阅读了 Wordpress 文档并尝试按照其中的步骤进行操作,但出了点问题。 其他一切正常,例如 the_title()、the_post_thumbnail()...只是这个自定义字段我不工作 :(

https://wordpress.org/support/article/custom-fields/ https://codex.wordpress.org/Function_Reference/register_post_type

自定义字段:

Functions.php

$supports = array (

'title',
'editor',
'thumbnail',
'custom-fields'

);

HTML

<?php  

     $args = array ('post_type' => 'produtos');
          $loop = new WP_Query( $args );

                  if ($loop->have_posts() ) {
                          while ($loop->have_posts() ) {
                            $loop->the_post();
                          ?>

    <div class="col-xl-2 col-lg-3 col-md-3 col-sm-4 col-md-3 col-12">
        <div class="produtos-head">
            <div class="img-fluid produtos-img">
                <?php the_post_thumbnail();  ?>
            </div>
        </div>
        <div class="produtos-titulo d-flex align-items-center justify-content-center">
            <?php the_title(); ?>

        </div>
        <div class="preco-original"> Price:R$
            <?php $original_price = get_post_meta($post->ID, 'original_price', true);
                                                if($original_price){ ?>
                <p>
                    <? echo $original_price; ?>
                </p>
                <?php 

  }else{ 

  }
?>
        </div>
        <div class="preco-promocional"> <span> Sale: </span>
            <span class="preco-promocional-number"> $ </span>

        </div>
        <button class="btn-vendedor"> Contact </button>
    </div>

    <?php
                }
              }
               ?>

        </div>
        </div>

使用 get_the_ID() 而不是 $post->ID 并且需要将 <? echo $original_price; ?> 更改为 <?php echo $original_price; ?>