Php 如何通过分类法获得simple_字段的值?
我试图通过分类法在一个简单的字段中获取图像,但我无法使用它,如果我进行变量转储,我会得到标题和其他内容,如链接和描述,但没有图像。。。是否有人知道如何访问此图像/简单_字段 我正在使用wordpress和phpPhp 如何通过分类法获得simple_字段的值?,php,wordpress,Php,Wordpress,我试图通过分类法在一个简单的字段中获取图像,但我无法使用它,如果我进行变量转储,我会得到标题和其他内容,如链接和描述,但没有图像。。。是否有人知道如何访问此图像/简单_字段 我正在使用wordpress和php $tt = get_terms('product_type', array()); foreach ($tt as $term) : print $term->name. ": "; $q = new WP_Query(array( 'post_type' =>
$tt = get_terms('product_type', array());
foreach ($tt as $term) :
print $term->name. ": ";
$q = new WP_Query(array(
'post_type' => 'ep-produkter',
'post_status' => 'publish',
'posts_per_page' => -1, // = all of 'em
'tax_query' => array(
'taxonomy' => $term->taxonomy,
'terms' => array( $term->term_id ),
'field' => 'term_id',
),
));
$first = true;
foreach ($q->posts as $item) :
var_dump($item);
print '<a href="'.get_permalink($item->ID).'">'
.$item->post_title.'</a>';
//here i want to echo the img
endforeach;
endforeach;
$tt=get_terms('product_type',array());
foreach($tt作为$term):
打印$term->name。": ";
$q=新的WP\U查询(数组(
“post_type”=>“ep produkter”,
“发布状态”=>“发布”,
“每页帖子”=>-1,//=所有帖子
“tax_query”=>数组(
“分类法”=>$term->taxonomy,
“术语”=>数组($term->term\u id),
'field'=>'term_id',
),
));
$first=true;
foreach($q->发布为$item):
var_dump(项目);
打印“”;
//这里我想回应一下img
endforeach;
endforeach;
您可以在for循环中使用以下功能打印帖子的特色图像:
//here i want to echo the img
echo get_the_post_thumbnail( $item->ID, 'thumbnail' );
或者,您可以获取图像url并使用img标记显示图像,如下所示:
//here i want to echo the img
$url = wp_get_attachment_url( get_post_thumbnail_id($item->ID) );
echo '<img src="$url" alt="" />';
//这里我要回显img
$url=wp\u获取附件\u url(获取帖子\u缩略图\u id($item->id));
回声';