无法在自定义分类存档页面上获取选项页面自定义字段
Posted
技术标签:
【中文标题】无法在自定义分类存档页面上获取选项页面自定义字段【英文标题】:Can't get option page custom fields on custom taxonomy archive page 【发布时间】:2016-04-06 16:32:16 【问题描述】:我使用 ACF 创建了选项页面,并为帖子和类别创建了自定义分类。我添加到我的标题 get_field 以获取徽标,它在大部分页面上都可以正常工作..
在自定义分类类别页面上,我没有得到任何数据。我尝试 var_dump 和 print_r 等等..它什么也没有得到,我在谷歌上找不到答案..
这是我的代码-
header.php
<?php
if (get_field('konimhakol_logo', 'options'))
$site_logo = get_field('konimhakol_logo', 'options');
echo '<a href="'. get_bloginfo('url') .'" title="'. get_bloginfo('name') .'"><img src="'. $site_logo['url'] .'" ></a>';
?>
functions.php
function create_businesses_post_type()
register_post_type('kh_businesses',
array(
'labels' => array(
'name' => __('עסקים'),
'singular_name' => __('עסק'),
'add_new' => __('הוסף עסק')
),
'menu_icon' => 'dashicons-admin-home',
'taxonomies' => array('category', 'post_tag'),
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'businesses'),
)
);
add_action( 'init', 'create_businesses_post_type' );
// Add Businesses Post Type to Archives
function archives_add_custom_types($query)
if(is_category() || is_tag() && empty($query->query_vars['suppress_filters']))
$query->set('post_type', array('kh_businesses'));
return $query;
add_filter( 'pre_get_posts', 'archives_add_custom_types' );
这是我的Homepage,这是Archive page
我很沮丧..提前谢谢
【问题讨论】:
【参考方案1】:您的 get_field() 调用应如下所示:
get_field('konimhakol_logo', 'option')
您有“选项”,但 ACF 的文档要求使用“选项”
http://www.advancedcustomfields.com/resources/get-values-from-an-options-page/
【讨论】:
谢谢,我刚刚试了一下,结果还是一样 这是一个干净的下划线主题,我自己添加了自定义帖子类型。也许我错过了什么? 在选项页面上调用自定义字段时,自定义帖子类型和分类档案应该是不相关的。我在所有页面模板和自定义文件上不断使用 get_field('', 'option') ,而且我从来没有遇到过任何问题。您是否有任何名为“option”或“options”的帖子类型或分类法可能导致冲突? 或者,您的主题是否正在使用“选项”或“选项”进行某些主题自定义,这可能会导致冲突。 这是我唯一的自定义帖子类型(企业),它是一个干净的下划线主题。我刚刚注意到,当我转到 nav-menus.php 选项屏幕时,只有企业,它们的类别在常规 WordPress 类别下【参考方案2】:好的,我发现了问题! 为了获得新类别下的帖子,我已将此代码添加到我的 functions.php 文件中-
// Add Businesses Post Type to Archives
function archives_add_custom_types($query)
if(is_category() || is_tag() && empty($query->query_vars['suppress_filters']))
$query->set('post_type', array('kh_businesses'));
return $query;
add_filter( 'pre_get_posts', 'archives_add_custom_types' );
但是当我删除它时,标题又回来了,但是我的业务类别下没有帖子...
【讨论】:
请问如何将自定义帖子类型添加到我的结果页面?我尝试了一些在 Google 上找到的代码,但对我没有任何效果以上是关于无法在自定义分类存档页面上获取选项页面自定义字段的主要内容,如果未能解决你的问题,请参考以下文章
php 在自定义帖子类型存档和一些自定义分类存档上强制命令到`menu_order`