我想,基本上你的问题是,如何在短代码中查询自定义帖子类型的帖子。您应该查看WordPress的WP\\U查询部分:https://codex.wordpress.org/Class_Reference/WP_Query
在我的示例代码中,我创建了一个快捷码,它显示了“我的自定义帖子类型”类型的最新发布帖子的标题:
<?php
    add_shortcode( \'shortcodename\', \'display_custom_post_type\' );
    function display_custom_post_type(){
        $args = array(
            \'post_type\' => \'my-custom-post-type\',
            \'post_status\' => \'publish\'
        );
        $string = \'\';
        $query = new WP_Query( $args );
        if( $query->have_posts() ){
            $string .= \'<ul>\';
            while( $query->have_posts() ){
                $query->the_post();
                $string .= \'<li>\' . get_the_title() . \'</li>\';
            }
            $string .= \'</ul>\';
        }
        wp_reset_postdata();
        return $string;
    }
?>
 由于短代码是在循环中执行的,因此应该使用
wp_reset_postdata() 完成查询后,主循环会像预期的那样再次工作。有关此功能的更多信息,请参见:
https://codex.wordpress.org/Function_Reference/wp_reset_postdata我希望,这会给你一个开始。