我能够在索引和单个帖子上显示转发器元盒。现在我想用
add_filter( \'the_content\', \'theme_slug_filter_the_content\' );
获取元值的我的代码
<?php
$data = get_post_meta($post->ID,"repeatable_fields",true);
echo \'<ul>\';
if (count($data) > 0){
foreach((array)$data as $p ){
if (isset($p[\'name\']) || isset($p[\'select\'])|| isset($p[\'url\'])){
echo \'<li>Number: \'.$p[\'name\'].\' Description: \'.$p[\'select\'].\' Price: \'.$p[\'url\'].\'</li>\';
}
}
}
echo \'</ul>\';
?>
我想我的代码是
function theme_slug_filter_the_content( $content ) {
$custom_content = \'YOUR CONTENT GOES HERE\';
$custom_content .= $content;
return $custom_content;
}
add_filter( \'the_content\', \'theme_slug_filter_the_content\' );
最合适的回答,由SO网友:Sadia Mehjabin 整理而成
你试过这个吗?希望这能奏效。
add_filter( \'the_content\', \'cd_display_quote\' );
function cd_display_quote( $content )
{
// We only want this on single posts, bail if we\'re not in a single post
// if( !is_single() ) return $content;
// We\'re in the loop, so we can grab the $post variable
global $post;
$data = get_post_meta($post->ID,"repeatable_fields",true);
echo \'<ul>\';
if (count($data) > 0){
foreach((array)$data as $p ){
if (isset($p[\'name\']) || isset($p[\'select\'])|| isset($p[\'url\'])){
echo \'<li>Number: \'.$p[\'name\'].\' Description: \'.$p[\'select\'].\' Price: \'.$p[\'url\'].\'</li>\';
}
}
}
echo \'</ul>\';
// Return the values: quote first, then the content
return $content;
}