Jason
Jason

Reputation: 415

Custom Post Type link with post page WordPress

I have create a custom post type and then displaying custom post data but when I click on read more button of that custom post it's giving me an error page not foundwhen I click on read more button it's pointing url like this domain.com/abc/my-custom-post here abc is custom post slug. I am sharing you what I did till now.

Custom Post Type

<?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' );
?>

Displaying custom post code

<?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();

?>

Let me know how to connect with post page when clicking read more button.

Upvotes: 1

Views: 1382

Answers (3)

Tanmay Patel
Tanmay Patel

Reputation: 1810

I have checked your code and it is perfect but Here you can follow the instructions as per given screenshot to fix your problem http://prntscr.com/mozub7 and this is reference link Hope your problem is fixed.

Upvotes: 1

Kazbek Kadalashvili
Kazbek Kadalashvili

Reputation: 340

Your code is working correctly. Try again to save the permalinks settings

Upvotes: 0

Mohammad Yousefi
Mohammad Yousefi

Reputation: 543

do you save permalink? in wp dash go >> settings>permalinks and save changes one time

Upvotes: 0

Related Questions