• Hi! every body! Please help me.

    I have a custom post type: product:

    add_action(‘init’, ‘create_product_post_type’);
    function create_product_post_type(){
    register_post_type(‘product’,
    array(
    ‘labels’ => array(
    ‘name’ => __(‘S?n ph?m’),
    ‘singular_name’ => __(‘S?n ph?m’),
    ‘add_new’ => __(‘Thêm m?i’),
    ‘add_new_item’ => __(‘Thêm m?i s?n ph?m’),
    ‘edit’ => __(‘Edit’),
    ‘edit_item’ => __(‘S?a th?ng tin’),
    ‘new_item’ => __(‘New Product’),
    ‘view’ => __(‘View Product’),
    ‘view_item’ => __(‘View Product’),
    ‘search_items’ => __(‘Tìm ki?m s?n ph?m’),
    ‘not_found’ => __(‘Kh?ng có s?n ph?m nào ???c tìm th?y’),
    ‘not_found_in_trash’ => __(‘Kh?ng có s?n ph?m nào ???c tìm th?y trong thùng rác’)
    ),
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘publicy_queryable’ => true,
    ‘exclude_from_search’ => false,
    ‘menu_position’ => 5,
    ‘menu_icon’ => get_stylesheet_directory_uri(). ‘/images/product.png’,
    ‘hierarchical’ => true,
    ‘query_var’ => true,
    ‘supports’ => array(
    ‘title’, ‘editor’, ‘comments’, ‘author’, ‘excerpt’, ‘thumbnail’,
    ‘custom-fields’
    ),
    ‘rewrite’ => array(‘slug’ => ‘product’, ‘with_front’ => false),
    ‘can_export’ => true,
    //’register_meta_box_cb’ => ‘call_to_function_do_something’,
    ‘description’ => __(‘Product description here.’)
    )
    );
    register_taxonomy(‘category’,’product’,array(‘hierarchical’=>true,’label’=>__(‘Danh m?c s?n ph?m’)));
    }

    But, I can’t display categorie of “product”, When i click into link category, It’s display all product in (custom post type)”product”.
    I want it displayed on the list that I has categorized but when clicked it displays all the products.

    So! I dont know why. Please! Help me!
    Sorry My English very bad:(
    Thanks alots

Viewing 2 replies - 1 through 2 (of 2 total)
  • Greetings,

    First, when pasting that much code in the future, please use Pastebin. This is mentioned in the forum guidelines, because it keeps your code from goofing things up.

    That said…
    I understand you want:
    https://mysite.com/my-product-name/
    But what you are getting is:
    https://mysite.com/custom-post-type-slug/my-product-name/

    That is the way it works, and you would be ill-advised to mess with this permalink structure. You are not alone — I understand your desire for this functionality — but it’s still not the way custom post types work.

    If you must have:
    https://mysite.com/my-product-name/
    then perhaps your products should be standard WordPress Pages, and you can add some taxonomy to define what type of products they are.

    Good luck,
    Paul

    Thread Starter luuducthuy

    (@luuducthuy)

    Thanks you Pauls. But it’s not i need.

    I do not display for each product category. I’ve tried several ways but could not. I do not know how. That is when I click on a category, then it does not display the products in that category as a default post.

    I’ts my problem i had.

    Please, help me.
    MY CODE DISPLAY PRODUCT ON CATEGORY. I wrote in category.php.

    <?php query_posts( array( 'post_type' => 'product', 'media' => 'print','post_per_page'=>-1,'caller_get_posts'=>1 ) );?>
                            <div class="l_product">
                               <?php if(have_posts()) : while(have_posts()) : the_post() ;?>
                            	<div class="product">
                                	<a>">
                                        <?php
        									if(has_post_thumbnail()){
        										the_post_thumbnail();
        									}
        							     ?>
                                    </a>
                                    <div class="m-shadow"></div>
                                    <h4 class="cut_text"><a>" title="<?php the_title_attribute(); ?>"><?php the_title()?></a></h4>
                                    <p class="price">Giá: <?php echo get_the_term_list($post->ID, 'gia', '', '', '');?> VND/m2 </p>
                                </div>
    
                               <?php endwhile;?>
                               <?php else: ?>
              					<p>Hi?n t?i ch?a có s?n ph?m m?i nào ???c ??ng lên website </p>
             				   <?php endif;
                                wp_reset_query();
                                ?>
                            </div><!-- .l_s_product -->

    [ Please do not bump, it’s not permitted here. ]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem about display product with custom post type’ is closed to new replies.