- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何限制此代码中的字符数?
.get_post_meta($post->ID,'smple1',true).
我试过以下方法:
$trim_length = 21; //desired length of text to display
$custom_field = 'smple1';
$value = get_post_meta($post->ID, $custom_field, true);
if ($value) {
echo '.rtrim(substr($value,0,$trim_length)) . ';
}
但是我收到服务器错误。我一定是缺少 endif 之类的东西?
非常感谢。
最佳答案
您需要获取元值,确保它在 false
中,然后使用 substr()
获取 21 个字符,如果字段较短,则根据 strlen()
的结果获取更少字符.
$length = 21;
$custom_field = 'smple1';
$value = get_post_meta( $post->ID, $custom_field, true );
if ( false !== $value ){
echo substr( $value, 0, (strlen($value) < $length)? strlen($value) : $length );
}
关于php - 限制 post_meta 中的字符(wordpress),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16906942/
我正在尝试查询 Wordpress 帖子。 我创建了一个自定义帖子类型 People。每个 people 帖子都有自定义字段 name、age、location、birthday 等.自定义字段是使用
如何限制此代码中的字符数? .get_post_meta($post->ID,'smple1',true). 我试过以下方法: $trim_length = 21; //desired length
我将查询限制为使用 6 个月前的显示帖子,效果很好。 但我需要它基于 post_meta 表中的日期而不是“post_date_gmt”。 在我的例子中,我有一个名为 payment_date 的 m
我使用以下代码来选择具有以下 post_meta 键的产品:_product_new、_product_almost_new 和 _product_old。 我的代码: add_action( 'wo
function yummy_sounds_custom(){ add_menu_page( __( 'Custom Menu Title', 'textdomain' ),
我正在使用 Wordpress 并尝试创建一个 View ,以便更轻松地查看和分析我的度假村数据。度假村数据存储在 Wordpress 的 post_meta 表中,并在称为“度假村”的自定义帖子类型
我想对 WordPress 站点(wp_postmeta 表)中的帖子元数据执行一些更新。已知的 good'ol 函数 update_post_meta() 正在完成这项工作,并且还将检查,如果 ke
我知道这是不对的,尽管这是可行的。 我需要找到给定半径和位置附近的所有帖子(作为收入),但我需要子查询 post_meta 中的经纬度信息。 它会伤害你的眼睛,所以在这里: /* lat -23.64
我正在处理亚马逊附属 wordpress 页面。为此,我使用 aws_signed_request 函数从亚马逊获取价格和链接。 这是返回 xml 的 aws_signed_request 函数:
我正在建立一个汽车服务数据库。每个汽车服务都可以维修多种型号的汽车。 存储汽车服务和类型之间的关系以便以后能够查询的最佳方式是什么? 我的选择是: 对于每辆车,将模型保存为 post_meta 作为单
我在 WooCommerce 中有 5000 多种产品,我正在寻找 SQL 查询来根据其 SKU 设置条形码。 “条形码”和“sku”都是自定义帖子元。基本上,类似于: UPDATE wp_postm
尝试在 WordPress 环境中根据当前选择的父 ID 递归选择数据库字段。 在 WordPress 方面: 我正在执行一个 pre_get_posts 过滤器以仅检索与用户元相关联的帖子。这很简单
我找到了几个关于如何“插入……”“不存在的地方”的解释,但这并没有解决我的问题。 我正在使用 Wordpress,我有一个名为 wp_posts 的表,其中包含帖子、产品、product_variat
我是一名优秀的程序员,十分优秀!