我正在开发一个使用FacetWP作为事件位置页面的站点,而其中一个关键功能不起作用。去年,另一个开发人员建立了一个自定义解决方案,列出FacetWP帖子,并按它们所处的状态对它们进行排序。他们对此使用了自定义分类法,但从那时起,插件和地图插件就有了破坏该解决方案的更新。
FacetWP背后的开发人员一直在帮助我重新设计自定义解决方案,但他现在无法使用,我仍然需要一些帮助。他指示我重做查询,删除自定义分类法,并使用一个自定义字段代替状态名,因为它与插件工作得更好。因此,对该模板的查询如下所示:
'location',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_key' => 'state',
'orderby' => array(
'meta_value' => 'ASC',
'title' => 'ASC',
),
);这部分工作很好,解决了我以前遇到的一个问题。我重新构建了模板的显示代码如下:
have_posts()) {
$state = get_field('state');
$show_header = (empty($prev_state) || $state != $prev_state);
$prev_state = $state;
$query->the_post();
$post_id = get_the_ID();
$title = get_the_title($post_id);
$distance = facetwp_get_distance($post_id);
$distance = (false !== $distance) ? round($distance, 1) . ' miles away' : '';
$coords = get_post_meta($post_id, 'location', true);
$content = get_the_content();
?>您可以从我正在测试的暂存服务器中看到它几乎正常工作,但不是100%正确。文章没有按状态正确地列出,并且在列表上面的状态标题是不正确的。
这是一个漫长的一天,我的大脑只是不知道我需要做什么来纠正这个问题。我肯定需要在正确的方向上轻轻一推。
发布于 2018-03-16 00:28:16
我终于修好了:
have_posts()) {
$query->the_post();
$state = get_post_meta(get_the_ID(), 'state', true);
$state_posts[$state][] = $post;
}
wp_reset_query();
foreach ($state_posts as $state_post => $state_title) {
?>
$single_listing) {
setup_postdata($single_listing);
$post_id = $single_listing->ID;
$title = get_the_title($post_id);
$distance = facetwp_get_distance($post_id);
$distance = (false !== $distance) ? round($distance, 1) . ' miles away' : '';
$coords = get_post_meta($post_id, 'location', true);
$content = get_the_content();
?>我在最后一个the_title循环中需要post数据时,在while循环中使用了诸如D3、the_content等的post数据,以便只将这些数据应用到单个帖子中。
发布于 2018-03-15 22:47:51
您需要做的就是在几个foreach循环中列出自定义字段值,如下所示:
have_posts()) {
$query->the_post();
$posts = $query->have_posts();
$post_id = get_the_ID();
$title = get_the_title($post_id);
$distance = facetwp_get_distance($post_id);
$distance = (false !== $distance) ? round($distance, 1) . ' miles away' : '';
$coords = get_post_meta($post_id, 'location', true);
$content = get_the_content();
foreach ($posts as $post) {
$state = get_field('state');
$state_posts[$state][] = $post;
}
}
foreach ($state_posts as $state_post => $state_title) {
?>https://wordpress.stackexchange.com/questions/296953
复制相似问题