如何显示自定义字段而不是 the_title

How to show a custom field instead of the_title

我有一个 WordPress 网站,我想显示当前类别中所有 post 的列表(当前 post 除外)。

我需要将名为 "test" 的特定 custom-field 的值用作锚文本,而不是 post 标题。

我如何编辑下面的代码以执行此操作并排除当前的 post?

    <?php
        global $post;
        $categories = get_the_category();
        foreach ($categories as $category) :?>
            <ul>
            <?php
                $posts = get_posts('numberposts=3&category='. $category->term_id);
                foreach($posts as $post) : ?>
                <li>
                    <a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
    </a>            </li>
            <?php endforeach; ?>
    <?php endforeach; ?>
            </ul>

这可能有效:

<?php

global $post;
$categories = get_the_category();
$currentID = get_the_ID();
foreach ($categories as $category) :?>
  <ul>
      <?php
      $posts = get_posts('numberposts=3&category='. $category->term_id);
          foreach($posts as $post) : 
            if ( $currentID != $post->ID ) {
              ?>                 
                $test_value = get_post_meta( $post->ID, 'test', true );
                ?>
                 <li>
                    <a href="<?php the_permalink(); ?>">
                       <?php if ( ! empty( $test_value ) ) {echo $test_value; } else { echo 'Nothing'; } ?>
                    </a>
                 </li><?php
              } ?>
          <?php endforeach; ?>
  </ul>
<?php endforeach; ?>