我创建了一个短代码,允许我传递这样的属性[product_swatch swatchtype="swatch"]
. 它在前端工作正常,但每次我更新页面时都会导致500个错误。如果未传递任何属性或属性未返回任何内容,则按照正常方式更新页面。
我很困惑,因为WP\\u DEBUG也没有显示任何内容。
以下是相关功能:
function product_swatch_shortcode($atts)
{
$swatch_shortcode_atts = extract( shortcode_atts( array(
\'swatchtype\' => \'\',
), $atts));
$swatch_args = array (
\'post_type\' => \'swatch\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'swatch-type\',
\'field\' => \'slug\',
\'terms\' => $swatchtype,
),
),
);
// The Query
$swatch_query = new WP_Query( $swatch_args );
// The Loop
if ( $swatch_query->have_posts() ) {
while ( $swatch_query->have_posts() ) {
$swatch_query->the_post();
$swatch_name = get_the_title();
$swatch_image_small = get_the_post_thumbnail_url( \'\', \'medium\' );
$swatch_image_big = get_the_post_thumbnail_url( \'\', \'full\' );
$interactive_designer_link = types_render_field( \'swatch-interactive-designer-link\', array(\'output\' => \'raw\') );
$preview_image = types_render_field( \'swatch-preview-image\', array(\'output\' => \'raw\') );
$swatch_id = strtolower( preg_replace(\'/\\s+/\', \'\', get_the_title()) );
$output = \'<a href="javascript:;" data-fancybox data-src="#\' . $swatch_id . \'" class="swatch"><img src="\' . $swatch_image_small . \'">\' . $swatch_name . \'</a>\';
$output .= \'<div id="\' . $swatch_id . \'" class="lightbox swatch-details">\';
$output .= \'<div class="swatch-col1"><h5>\' . $swatch_name . \'</h5><img src="\' . $swatch_image_big . \'">\';
$output .= \'<a href="\' . $interactive_designer_link . \'" class="btn" style="margin:30px 0;">VIEW PRODUCT IN SIMULATION</a></div>\';
$output .= \'<div class="swatch-col2"><img src="\' . $preview_image . \'"></div></div>\';
echo $output;
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
}