最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

debug - Correct my shortcode for displaying a category?

programmeradmin0浏览0评论
function diwp_create_shortcode_arts_post_type(){
    
    $atts = shortcode_atts( array(
        'type' => ' ',
    ), $atts );
 
    $args = array(
                    'post_type'      => 'arts',
                    'posts_per_page' => '10',
                    'post_status' => 'publish',
                    'tax_query'     => array( array(
                                'taxonomy'  => 'Types',
                                'field'     => 'term_id',
                                'terms'     =>  '10', //(What should I do here, otherwise my code is correct, here I just put category id directly but I wanna display a specific category posts)
                            ) )
                 );
 
    $query = new WP_Query($args);
    if($query->have_posts()) :
        while($query->have_posts()) :
            $query->the_post() ;      
        $result .= '<div class="art-item">';
        $result .= '<div class="art-image">' . get_the_post_thumbnail() . '</div>';
        $result .= '<div class="art-name">' . get_the_title() . '</div>';
        $result .= '<div class="art-desc">' . get_the_content() . '</div>';
        $result .= '</div>';
        endwhile;
        wp_reset_postdata();
    endif;    
    return $result;            
}
add_shortcode( 'arts-list', 'diwp_create_shortcode_arts_post_type' ); 
发布评论

评论列表(0)

  1. 暂无评论