个性化阅读
专注于IT技术分析

按post类型查询-未显示任何内容

我正在尝试显示自定义帖子类型的帖子, 但是什么也不显示。

我已经使用CPT UI / ACF设置了所有自定义字段, 并且在显示部分之前一切似乎都很顺利。

这是我创建的blog.php模板:

<?php
/**
 * Template Name: Blog template
 *
 * @package Hestia
 * @since Hestia 1.0
 */

get_header();
?>

<?php

$args = array(
    'post_type' => 'blog', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
?>


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

    <h1><?php the_field('main_title');?><h1>
    <img src="<?php the_field('header_image');?>" alt="" />
    <p><?php the_field('paragraph_1');?></p>
    <img src="<?php the_field('image_1');?>" alt="" />
    <p><?php the_field('paragraph_2');?><h1>
    <img src="<?php the_field('image_2');?>" alt="" />
    <p><?php the_field('paragraph_3');?><h1>
    <img src="<?php the_field('image_3');?>" alt="" />



<?php endwhile; ?>

    <?php get_footer(); ?>

function cptui_register_my_cpts_blog() {

    /**
     * Post Type: Blog.
     */

    $labels = array(
        "name" => __( "Blog", "hestia-pro" ), "singular_name" => __( "blog", "hestia-pro" ), "menu_name" => __( "Blog", "hestia-pro" ), "all_items" => __( "All posts", "hestia-pro" ), "add_new" => __( "Add new", "hestia-pro" ), "add_new_item" => __( "Add new post", "hestia-pro" ), );

    $args = array(
        "label" => __( "Blog", "hestia-pro" ), "labels" => $labels, "description" => "", "public" => true, "publicly_queryable" => true, "show_ui" => true, "show_in_rest" => false, "rest_base" => "", "has_archive" => false, "show_in_menu" => true, "exclude_from_search" => false, "capability_type" => "post", "map_meta_cap" => true, "hierarchical" => false, "rewrite" => array( "slug" => "blog", "with_front" => true ), "query_var" => true, "menu_icon" => "dashicons-welcome-write-blog", "supports" => array( "title", "editor", "thumbnail" ), );

    register_post_type( "blog", $args );
}

add_action( 'init', 'cptui_register_my_cpts_blog' );

‘post_type’是正确的, 字段名称也是如此。它们都与自定义字段匹配, 但是由于某些原因, 什么都没有显示。

谢谢!


#1


将has_archive设置为true。有同样的问题, 并解决了它。

赞(0)
未经允许不得转载:srcmini » 按post类型查询-未显示任何内容

评论 抢沙发

评论前必须登录!