我已经为我的网站上的位置创建了一个自定义帖子类型,我想用短代码完整地显示每个帖子。我对创建短代码很陌生,我正努力想办法解决它。我想按slug这样显示帖子:[stefan\\u location slug=“Aspley”]但我无法让它工作。我知道我可能离得太远了,所以欢迎任何建议!!
function cpt_content_func($atts){
$post = \'\';
$content = \'\';
extract( shortcode_atts( array(
\'slug\' => null,
), $atts ) );
$args = array(
\'name\' => $slug,
\'post_type\' => \'location\',
\'numberposts\' => 1
);
$post = get_posts( $args );
if ( !empty( $post ) ) {
$content = $post[0]->post_content;
}
return $content;
}
add_shortcode(\'stefan_location\',\'stefan_location\');