自定义帖子类型链接与帖子页面WordPress

时间:2019-02-23 07:49:30

标签: php wordpress custom-post-type

我已经创建了一个自定义帖子类型,然后显示自定义帖子数据,但是当我单击该自定义帖子的“阅读更多”按钮时,它给我一个错误page not found,当我单击“阅读更多”按钮时,它指向的网址是这样的domain.com/abc/my-custom-post这里abc是自定义帖子。我正在分享你到目前为止的工作。

自定义帖子类型

<?php
    function create_posttype() {

    register_post_type( 'abc',
    array(
    'labels' => array(
    'name' => __( 'ABC' ),
    'singular_name' => __( 'ABC' ),
    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', )
    ),
    'public' => true,
    'has_archive' => true,
    'rewrite' => array('slug' => 'abc'),
    )
    );
    }
    add_action( 'init', 'create_posttype' );
?>

显示自定义邮政编码

<?php
    $args = array(
    'post_type' => 'abc',
    'posts_per_page' => -1
    );
    $wp_query = new WP_Query($args);
    while($wp_query->have_posts()) : $wp_query->the_post();
    echo get_field('featured_image');
    the_title();
    echo get_the_excerpt();
    endwhile;
    wp_reset_query();

?>

让我知道单击“更多”按钮时如何与帖子页面建立联系。

3 个答案:

答案 0 :(得分:1)

我已经检查了您的代码,它是完美的,但是在这里您可以按照给定的屏幕快照中的说明来解决问题http://prntscr.com/mozub7,这是reference link希望您的问题已解决。

答案 1 :(得分:0)

您保存永久链接吗? 在wp dash中进入>>设置>永久链接并保存一次更改

答案 2 :(得分:0)

您的代码正常工作。重试以保存永久链接设置

相关问题