繁体   English   中英

无法在WP主页中查看自定义帖子类型的帖子

[英]can't view custom post type posts in WP home page

我正在尝试在WordPress中查看自定义帖子类型的帖子,并停留在下面的代码中。

$args = array(
    'type'      => 'theslider',
    'orderby'   => 'date',
    'order'     => 'DESC',
    'cat'       => 23
);

$lasts = new WP_Query( $args );

if( $lasts->have_posts() ):

    while( $lasts->have_posts() ): $lasts->the_post();

        the_title( sprintf('<a href="%s"><div class="pt10 title">', esc_url( get_permalink() ) ),'</div></a>' ); 

    endwhile;

endif;

wp_reset_postdata();

此代码适用于默认帖子类型。 而且“自定义帖子类型”功能在管理面板中效果很好。

如何在WordPress主页上查看自定义帖子类型的帖子。

得到它了。 在此处发布以供将来参考。

<?php 
$args = array(
    'post_type'=> 'theslider',
    'orderby'   => 'date',
    'order'     => 'DESC'
);              

$the_query = new WP_Query( $args );
if($the_query->have_posts() ) : 
    while ( $the_query->have_posts() ) : $the_query->the_post(); 

        the_title();

    endwhile; 

else: 

    echo '<p>Nothing Here.</p>';

endif; 

wp_reset_postdata(); 

?>

而已。 它会获取并查看自定义帖子类型的帖子:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM