为什么get_post_meta不起作用? [英] Why isn't get_post_meta working?

查看:95
本文介绍了为什么get_post_meta不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的Wordpress问题-get_post_meta不会检索自定义字段值.这是从自定义字段中提取的代码:

Simple Wordpress problem - get_post_meta is not retrieving custom field values. Here's the code that is pulling from the custom fields:

<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; ?>" />

在生产中,这是我得到的HTML:

In production, this is the HTML I get:

<img alt="Post Title" src="http://***.com/wp-content/plugins/jquery-slider-for-featured-content/scripts/timthumb.php?src=/&amp;h=50&amp;w=80&amp;zc=1">

您可以看到字符串中的src =点为空-好像没有任何内容在发布.我已经隔离并仅回显了get_post_meta,它是一个空白.我100%确定帖子中的名称正确-我在这里缺少什么明显的地方吗?

You can see the src= point in the string is empty - as if there is nothing posting from it. I have isolated and echo'd just the get_post_meta and it's a whitespace. I am 100% sure it's named correctly within the post - is there something glaring I'm missing here?

推荐答案

使用phpmyadmin在wp_posts和wp_postmeta表中搜索术语"slider_image".然后查看包含它的行,看看里面是否有任何东西.

Search for the term "slider_image" in the wp_posts and wp_postmeta tables using phpmyadmin. Then view the row that has it to see if there's anything inside.

也请尝试更改自定义值的名称作为测试,以查看是否可行.我使用此确切的代码执行与您相似的操作,并且可以正常工作:

Also try changing the name of the custom value as a test and see if that works. I use this exact code to do something similar to you and it works:

<p><a href="<?php echo get_post_meta($post->ID, 'resume', true) ?>"><img src="<? bloginfo('template_url'); ?>/img/downloadresume.png"></a></p>

这篇关于为什么get_post_meta不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆