0

i make a custom post type in WordPress and i also make its separate two pages single-acme_product.php, archive-acme_product.php but the issue is when i upload the post from custom post type its show index.php

here is my code of function

function new_post_type_wp(){

    register_post_type('acme_product',
            array(
                'labels' => array(
                    'name' => __('Products'),
                    'singular_name' => __('Product')
                ),
                'public' => true,
                'has_archive' => true,
            )
        );
}
add_action('init','new_post_type_wp');

please tell me how to i navigate my custom post to specific custom page i also read wordpress codex its very help full i follow its method but my issue is same kindly help me

reference link : https://codex.wordpress.org/Post_Types

  • Please re-save your permalinks. Settings > Permalinks > Save. – deflime Sep 18 '15 at 18:11
  • no its not the issue i did it but the result is same – Hafiz Usman aftab Sep 18 '15 at 18:30
  • 1
    Have you tried using a core-bundled theme to be sure some code elsewhere in your theme is not causing the issue? – Milo Sep 18 '15 at 19:05
  • No I no try this May b this possible I implement this on another theme and tell you what the status – Hafiz Usman aftab Sep 18 '15 at 19:17
  • @Milo thanks dear your point out exact issue i perform this on default template and its work on default template then i copy paste the code its work not know what happen but i am happy thanks :) – Hafiz Usman aftab Sep 19 '15 at 6:34
0

Since WordPress is having trouble recognizing your custom template files, you could use this instead.

Insert into your single.php file. Based on your description above, it sounds like you don't have a single.php file so you will likely have to create one. If you do already have a single.php file then there is likely still some confusion with your exact problem because a custom post would only display the index.php template if there was no single.php. Or you could just be confusing the two.

<?php 
  if( get_post_type == 'acme_product' ) {
    // Put the template code to display the custom post type post

  } else {
    // Code for all other posts

  }
?>

This will work in any of the default WordPress post related template files like categories, archives, etc.

  • it's probably better to figure out why something that should be working isn't working. – Milo Sep 18 '15 at 19:14
  • Agreed, but I'd like to provide him with the option just in case. I am hoping someone has another idea to solve his problem. – deflime Sep 18 '15 at 19:17
-3

Alright, if I am not wrong with your request, below solutions may help. 1. make you sing-acme_product.php as a template, eg:

   <?php
   /**
   Template Name: the new of the template
   */
  1. Use WP_Query, eg:

    $products = new WP_Query('post_type = products'); if($products->have_posts()) : while($products->have_posts()):$products->the_post();

    endwhile; endif; wp_reset_postdata();

Hope this will help.

  • dear i make a custom post type and i just want i show my custom posts on single-acme_product.php , the issue i make a separate page single-acme_product.php for custom posts reference link codex.wordpress.org/Post_Types but instead the posts show on single-acme_product.php they show on index.php i just want to show these post on my single-acme_product.php you got it ?? – Hafiz Usman aftab Sep 18 '15 at 18:26
  • Why do you want to do this, it will complicate things even more, and btw, how will you handle single posts – Pieter Goosen Sep 18 '15 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.