我一直在到处寻找,但仍然不明白如何在我的站点上显示来自自定义Post类型的信息(为新客户端接管站点)。
前面的开发人员已经设置了一些自定义字段,如下面的thumb_title和resource_url:
'fields' => array(
// Thumbnail Title
array(
'name' => esc_html__( 'Thumbnail Title', 'textdomain' ),
'id' => "{$prefix}thumb_title",
'type' => 'text',
'desc' => 'i.e. Project Management',
),
// Resource URL
array(
'name' => esc_html__( 'Link to Resource', 'textdomain' ),
'id' => "{$prefix}resource_url",
'type' => 'text',
'desc' => 'Enter the resource URL, i.e. /resource/project-management',
),
),我可以很好地显示通常的the_title和the_content,这是我无法显示的其他字段,它让我发疯了。
以下是我对这一页的看法:
'resources_cta', 'posts_per_page' => 10 );
$the_query = new WP_Query( $args );
$thumb_title = get_post_meta( get_the_ID(), 'thumb_title', true );
?>
have_posts() ) : ?>
have_posts() ) : $the_query->the_post(); ?>
ID, 'thumb_title', true );
?>
the little book of
FIND OUT MORE我需要在接下来的几天内解决这个问题,所以任何帮助都是非常感激的。
提前谢谢。
发布于 2019-02-04 22:49:57
看起来你想从ACF那里得到价值吗?如果是这样,您可以使用get_field:
$thumb_title = get_field( 'thumb_title', get_the_ID();But wait:这将无法工作,因为:
'id' => "{$prefix}thumb_title",{$prefix}部件是在该文件的某个位置定义的,它正在创建一个完整的字段名。您需要在对get_field的调用中包括这一点:
// In your file adding fields somewhere:
$prefux = 'myprefix_';
// In your template:
$thumb_title = get_field( 'myprefix_thumb_title', get_the_ID() );向我们展示在第一个块中定义$prefix的行可能会有所帮助。此外,如果这些只是普通的WordPress元字段,则只需执行以下操作:
$thumb_title = get_post_meta( get_the_ID(), 'myprefix_thumb_title', true );https://wordpress.stackexchange.com/questions/327674
复制相似问题