我正在使用高级自定义字段插件-尽管我不确定这是否相关。尽管如此,我无法使用此方法使substr()工作:
$givchars = 5;
$postgiv = the_sub_field(\'get_involved_text\');
$modgiv = substr($postgiv, 0, $givchars);
echo \' \' .$modgiv. \' \';
但是,执行此操作时,substr()确实起作用:
$second_query = new WP_Query( $args );
if ( $second_query->have_posts() ):
while( $second_query->have_posts() ) : $second_query->the_post();
$titlechars = 5; // Character Limit
$posttitle = get_the_title();
$modtitle = substr($posttitle, 0, $titlechars);
$attachment_id = get_field(\'image\');
$size = \'customfeatins\'; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size ) . \'http://placehold.it/136x90\';
echo \'<article>
<img src="\' . $image[0] . \'" alt="\' . get_the_title() .\'" width="136" height="90" />
<h3>\' . $modtitle .\'</h3>
<p class="date">\' . get_the_date() .\'</p>
</article>
\';
endwhile;
endif;
我只是在学习WordPress,我的php技能非常有限,我是否完全忽视了什么?
最合适的回答,由SO网友:s_ha_dum 整理而成
在我看来the_sub_field
回显内容。它从未被退回substr
继续工作。你需要get_sub_field
.
$givchars = 5;
$postgiv = get_sub_field(\'get_involved_text\');
$modgiv = substr($postgiv, 0, $givchars);
echo \' \' .$modgiv. \' \';