我想使用WordPress默认自定义字段提取子标题文本?我使用这个短代码。但不显示任何文本?
//Shortcode: [lplist catname="" lpimgbg="" lpcatheading="" lpbtnurl=""]
function hm_post_list_shortcode($atts, $content) {
ob_start();
$plistshortcode = shortcode_atts( array(
\'catname\'=>\'$catatt\',
\'lpimgbg\' => \'http://localhost/example.com/wp-content/uploads/2019/04/rotating-Whetstone-bass-fishing.jpg\',
\'lpcatheading\' => \'Heading Here\',
\'lpbtnurl\' => \'https://www.google.com\'
), $atts);?>
<div class="lpcontainer" style="background-image: url(<?php echo esc_url($plistshortcode[\'lpimgbg\']); ?>);">
<div class="lpcontent-box">
<h3><?php echo esc_html($plistshortcode[\'lpcatheading\']); ?></h3>
<div class="lplistitem">
<?php
$the_query = new WP_Query(array(
\'posts_per_page\' => -1,
\'category_name\' => $plistshortcode[\'catname\']
));?>
<?php while($the_query->have_posts()) : $the_query->the_post(); ?>
//Wordpress Default custom field
<?php $sub_heading = get_post_meta($post->ID, \'sub_heading\', true);?>
<a href="<?php echo esc_url(the_permalink()); ?>"><?php echo $sub_heading; ?></a>
<?php endwhile;
wp_reset_postdata();
?>
</div>
<div class="lpbtncontainer">
<a href="<?php echo esc_url($plistshortcode[\'lpbtnurl\']); ?>"><?php echo esc_html(\'View Full List\');?></a>
</div>
</div>
</div>
<?php $hm_postlist = ob_get_clean();
return $hm_postlist;
}
add_shortcode( \'lplist\', \'hm_post_list_shortcode\' );