Попытка получить как пользовательский тип сообщения, так и сообщения для отображения на страницах тегов и категорий - PullRequest
0 голосов
/ 24 мая 2011

Я создал собственный тип записи, который настроен на использование готовых тегов и категорий, которые используют записи. Однако, если я нажму на ссылку тега или категории, в архиве будут показаны только сообщения с этим тегом, а не мой пользовательский тип сообщения. Я пробовал несколько способов исправить это, но они, похоже, не работают. Мой код:

// Add Resource Post Type

add_action('init', 'hallam_init');

function hallam_init() {
        // set up the labels
        $labels = array(
                'name' => _x('Resources', 'post type general name'),
                'singular_name' => _x('Resource', 'post type singular name'),
                'add_new' => _x('Add New', 'resource'),
                'add_new_item' => __( 'Add New Resource' ),
                'edit_item' => __( 'Edit Resource' ),
                'new_item' => __( 'New Resource' ),
                'view_item' => __( 'View Resource' ),
                'search_items' => __( 'Search Resources' ),
                'not_found' =>  __( 'No resources found' ),
                'not_found_in_trash' => __( 'No respources found in Trash' ),
                'parent_item_colon' => ''
        );

        // set up the args
        $args = array (
                'labels' => $labels,
                'public' => true,
                'publicly_queryable' => true,
                'show_ui' => true,
                'query_var' => true,
                'rewrite' => array (
                        'slug' => 'resources'
                ),
                'capability_type' => 'post',
                'hierarchical' => false,
                'menu_position' => 5,
                'supports' => array(
                        'title',
                        'editor',
                        'author',
                        'thumbnail',
                        'excerpt',
                        'comments'
                ),
                'taxonomies' => array(
                        'collection',
                        'category',
                        'post_tag'
                ),
                'has_archive' => true
        );

        register_post_type('ht_resource', $args);
}

// Add Taxonomy

register_taxonomy('collection', 'ht_resource', array(
        'hierarchical' => true,
        'label' => 'Collections',
        'query_var' => true,
        'rewrite' => true
));

// Fix the archives

    add_filter( 'pre_get_posts', 'add_to_query' );

    function add_to_query( $query ) {
        // if ( is_home() ) {
            if( $query->query_vars['suppress_filters'] ) // TODO check if necessary
                return $query;
            $supported = $query->get( 'post_type' );
            if ( !$supported || $supported == 'post' )
                $supported = array( 'post', 'ht_resource' );
            elseif ( is_array( $supported ) )
                array_push( $supported, 'ht_resource' );
            $query->set( 'post_type', $supported );
            return $query;
        //}
    }

Я что-то упускаю из виду?

1 Ответ

0 голосов
/ 04 августа 2011

Можете ли вы попробовать это, добавив файл functions.php вашей темы? Надеюсь, это сработает

function query_post_type($query) {
  if(is_tag()) {
        $query->set('post_type',$post_types=get_post_types('','names'));
        return $query;
    }
}
add_filter('pre_get_posts', 'query_post_type'); 

Thnx

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...