WordPress.org

Ready to get started?Download WordPress

Forums

Need help on displaying custom post types (3 posts)

  1. dhaval_jani
    Member
    Posted 1 year ago #

    Hi everyone,

    First of all i would like to thank you all in advance for helping me out and here is my problem :

    i am into this situation where i am not able to fetch custom post-type in single and archives.

    Here is what i have done :

    functions.php:--

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    register_post_type( 'products',
    array(
    'labels' => array(
    'name' => __( 'Featured Products' ),
    'singular_name' => __( 'Featured Product' )
    ),
    'public' => true,
    'has_archive' => true,
    )
    );
    }

    Then I am getting the data when i am querying posts from custom post type. But when i click on the permalink, I get 404 error.

    I researched a bit and found that i will need separate files for that so I created even single-products.php and archive-products.php but still not getting the content of the post.

    Please help me on this

  2. Hello.

    When you create a custom post type and get a 404 when you click on a "single" post of your CPT, you will need to refresh your permalinks. It is really that simple :-) Go to Settings > Permalinks, choose a different structure, save, then revert back to your original structure and save again.

  3. FYI this is a known bug that will be fixed in WordPress 3.6
    BUG: Changing permalinks to a custom structure returns 404 on custom post types

Topic Closed

This topic has been closed to new replies.

About this Topic