我有一个自定义帖子类型的网站,以及一些使用高级自定义字段(ACF)创建的自定义字段。我修改了一个归档站点(archive sammenligne.php),它以我想要的方式显示数据,但是当我尝试在页面上使用WP查询提取数据时,我没有得到任何输出。如果我使用标准的WordPress标题,我会得到输出。我假设与自定义字段的链接有关;但他们在归档页面上工作。
我需要在WordPress页面上运行查询,而不是在存档中,因为我希望在循环上方有帖子内容。下面的代码保存为页面模板。
我经营Genesis Metro Pro和WordPress。
提前谢谢。
<?php
add_filter( \'genesis_pre_get_option_site_layout\', \'__genesis_return_full_width_content\' );
function sk_display_custom_fields() {
/*Custom fields/*
$navn = get_field( \'navn\' );
$type = get_field( \'type\' );
$fordeler = get_field( \'fordeler\' );
/*Wordpress loop*/
$arg = array(
\'post_type\' => \'sammenligne\',
\'posts_per_page\' => 10,
\'order\' => \'DESC\',
\'post_status\' => \'publish\'
);
$query = new WP_Query($arg);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
echo \'<h2>\' . $navn . \'</h2>\';
endwhile;
endif;
wp_reset_query();
}
add_action( \'genesis_entry_header\', \'sk_display_custom_fields\' );
genesis();