dma*_*exe 1 php wordpress templates wordpress-thesis-theme
简单的Wordpress问题 - get_post_meta没有检索自定义字段值.这是从自定义字段中提取的代码:
<img src="<?php echo FCG_PLUGIN_URL; ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, 'slider_image', true); ?>&h=250&w=400&zc=1" alt="<?php echo $post_title; ?>" />
Run Code Online (Sandbox Code Playgroud)
在制作中,这是我得到的HTML:
<img alt="Post Title" src="http://***.com/wp-content/plugins/jquery-slider-for-featured-content/scripts/timthumb.php?src=/&h=50&w=80&zc=1">
Run Code Online (Sandbox Code Playgroud)
你可以看到字符串中的src = point是空的 - 好像没有任何帖子从中发布.我已经隔离并回显了get_post_meta,它是一个空格.我100%肯定它在帖子中的名字是正确的 - 有什么东西在我这里丢失吗?
小智 7
如果你在循环中调用get_post_meta那么你应该调用get_post_meta(get_the_id(), 'YOURKEY', true)而不是get_post_meta($post->ID, 'YOURKEY', true)
当你在循环中调用get_post_meta时会发生奇怪的事情.在某些主题中,开发人员在开始时破解$ post并且get_post_meta停止工作,因此这也是针对这些特定情况的解决方案之一.