Новые сообщения не появляются, если я добавляю их в новую ленту пользовательских сообщений. Wordpress - PullRequest
0 голосов
/ 01 июля 2019

У меня проблемы с печатью нового сообщения, если я создаю его в новом пользовательском сообщении, которое я добавил вручную в WordPress. Вы можете увидеть код ниже:

Функция, которую я использую для добавления пользовательского типа сообщения

   function custom_post_type() {

    // Set UI labels for Custom Post Type
        $labels = array(
            'name'                => _x( 'Latest News', 'Post Type General Name', 'OSS' ),
            'singular_name'       => _x( 'Latest News', 'Post Type Singular Name', 'OSS' ),
            'menu_name'           => __( 'Latest News', 'OSS' ),
            'parent_item_colon'   => __( 'Parent Latest News', 'OSS' ),
            'all_items'           => __( 'All Latest News', 'OSS' ),
            'view_item'           => __( 'View Latest News', 'OSS' ),
            'add_new_item'        => __( 'Add New News', 'OSS' ),
            'add_new'             => __( 'Add New News', 'OSS' ),
            'edit_item'           => __( 'Edit News', 'OSS' ),
            'update_item'         => __( 'Update News', 'OSS' ),
            'search_items'        => __( 'Search Latest News', 'OSS' ),
            'not_found'           => __( 'Not Found Any News', 'OSS' ),
            'not_found_in_trash'  => __( 'News Not found in Trash', 'OSS' ),
        );

    // Set other options for Custom Post Type

        $args = array(
            'label'               => __( 'Latest News', 'OSS' ),
            'description'         => __( 'Make new post in latest news page', 'OSS' ),
            'labels'              => $labels,
            // Features this CPT supports in Post Editor
            'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
            // You can associate this CPT with a taxonomy or custom taxonomy. 
            'taxonomies'          => array( 'genres' ),
            /* A hierarchical CPT is like Pages and can have
            * Parent and child items. A non-hierarchical CPT
            * is like Posts.
            */ 
            'hierarchical'        => false,
            'public'              => true,
            'show_ui'             => true,
            'show_in_menu'        => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => true,
            'menu_position'       => 5,
            'can_export'          => true,
            'has_archive'         => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
            'capability_type'     => 'page',
    // This is where we add taxonomies to our CPT
            'taxonomies'          => array( 'category' ),
        );

        // Registering your Custom Post Type
        register_post_type( 'news', $args );

    }

    /* Hook into the 'init' action so that the function
    * Containing our post type registration is not 
    * unnecessarily executed. 
    */

    add_action( 'init', 'custom_post_type', 0 );

Итак, у меня есть два пользовательских поста. Для одного я просто изменяю имя на События, которые раньше назывались «Посты» по умолчанию. Другой я создал вручную и назвал его «Последние новости».

Когда я делаю новое сообщение в событиях, оно выглядит хорошо, в противном случае, если я делаю одно в последних новостях, это не так.

Здесь вы можете увидеть, как я пытаюсь распечатать его по ID категории:

<?php
                /* Start the Loop */
                while ( have_posts() ) :
                    the_post();

                    $posts = get_posts ("category=3&orderby=date&numberposts=6"); 
            ?> 
            <?php if ($posts) : ?>
            <?php foreach ($posts as $post) : setup_postdata ($post); ?>

Я уже пытался обновить предварительные ссылки, это не помогает

P.S. Решил это с помощью кода ниже на странице, когда я попытался напечатать пользовательские сообщения:

<?php
    if ( get_query_var('paged') ) $paged = get_query_var('paged');
    if ( get_query_var('page') ) $paged = get_query_var('page');

    $query = new WP_Query( array( 'post_type' => 'name of the category', 'paged' => $paged ) ); //here place the name of your category

    if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>

<?php endwhile; wp_reset_postdata(); ?>
<!-- show pagination here -->
<?php else : ?>
<!-- show 404 error here -->
<?php endif; ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...