php 在主博客和存档页面上显示WordPress自定义帖子类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在主博客和存档页面上显示WordPress自定义帖子类型相关的知识,希望对你有一定的参考价值。

<?php

/**
 * Show WordPress custom post types on the main blog and archive pages
 * 
 * @param WP_Query $query
 **/
function show_custom_post_types( $query ) {
  
  // Show all custom post types on main blog and archive pages
  if ( $query->is_main_query() && ( is_home() || ( is_archive() && !is_post_type_archive() ) ) ) {
    $custom_post_types = get_post_types( array( 
      'public' => true,
      '_builtin' => false,
    ) );
    $post_types = array_merge( array('post'), $custom_post_types );
    $query->set( 'post_type', $post_types );
  }
  
}

add_action( 'pre_get_posts', 'show_custom_post_types' );

以上是关于php 在主博客和存档页面上显示WordPress自定义帖子类型的主要内容,如果未能解决你的问题,请参考以下文章