我的网站正在运行Generate Press theme并使用Elementor作为页面生成器。
我的目标是创建一个显示CPT及其元字段的短代码。当我在页面上使用快捷码时,效果很好。然而,当我在Elementor下使用它时,当我尝试在后端编辑帖子时,会出现以下错误:“在您的页面中找不到内容区域”https://docs.elementor.com/article/56-content-area-not-found
据推测,这是因为缺少\\u内容的函数。
我尝试过将函数添加到短代码中,但仍然没有任何结果。Elementor支持没有帮助。也许你可以解释为什么会发生这种情况。这里有代码:
function vehiculos_func( $atts ){
$arg = array (
\'post_type\' => \'vehiculo\'
);
$query = new WP_Query($arg);
if($query ->have_posts()) {
//echo "<ul>";
// echo \'<div class="grid-container">\';
$html ="<ul>";
$html .= \'<div class="grid-container">\';
while ($query ->have_posts()) {
$query->the_post();
$year = get_post_meta(get_the_id(), \'vehicle_year\', true);
$kilometers = get_post_meta(get_the_id(), \'vehicle_kilometers\', true);
$transmission = get_post_meta(get_the_id(), \'vehicle_transmission\', true);
$doors = get_post_meta(get_the_id(), \'vehicle_doors\', true);
$seats = get_post_meta(get_the_id(), \'vehicle_seats\', true);
$power = get_post_meta(get_the_id(), \'vehicle_power\', true);
$color = get_post_meta(get_the_id(), \'vehicle_color\', true);
$fuel = get_post_meta(get_the_id(), \'vehicle_fuel\', true);
$html .= \'<span class="nombre">\'.get_the_title().\'</span>\';
$html .= \'<li class="grid-33">\';
$html .= \'<div class="vehiculo">\';
$html .= \'<div class="separa-20"></div>\';
$html .= \'<span class="nombre">\'.get_the_title().\'</span>\';
$html .= \'<p>\'.get_the_content().\'</p>\';
$html .= \'<span class="atributo">\'.$kilometers.\'| \'.$fuel.\'| \'.\'Año //\'.$year.\'</span>\';
$html .= \'<div class="separa-10"></div>\';
$html .= \'<span class="precio">Desde 4000€\';
$html .= \'<div class="separa-20"></div>\';
$html .= \'<button type="button" class="btn-small btn-default">Ver //Coches</button>\';
$html .=\'</div>\';
$html .=\'</li>\';
}
$html .= \'</div>\';
$html .= "</ul>";
}
return $html;
}
add_shortcode( \'vehiculos\', \'vehiculos_func\' );