رفتن به مطلب

مشکل نمایش ندادن مطالب یک دسته خاص از پست های سفارشی


پست های پیشنهاد شده

سلام دوستان من برای یک پوسته یک پست سفارشی product اضافه کردم با استفاده از کد زیر : 

function custom_post_type() {
    // Set UI labels for Custom Post Type
    $labels = array(
    'name'                => _x( 'products', 'Post Type General Name', 'twentythirteen' ),
    'singular_name'       => _x( 'product', 'Post Type Singular Name', 'twentythirteen' ),
    'menu_name'           => __( 'Products', 'twentythirteen' ),
    'parent_item_colon'   => __( 'Parent Product', 'twentythirteen' ),
    'all_items'           => __( 'All products', 'twentythirteen' ),
    'view_item'           => __( 'View Product', 'twentythirteen' ),
    'add_new_item'        => __( 'Add New Product', 'twentythirteen' ),
    'add_new'             => __( 'Add New', 'twentythirteen' ),
    'edit_item'           => __( 'Edit Product', 'twentythirteen' ),
    'update_item'         => __( 'Update Product', 'twentythirteen' ),
    'search_items'        => __( 'Search Product', 'twentythirteen' ),
    'not_found'           => __( 'Not Found', 'twentythirteen' ),
    'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
    );
    // Set other options for Custom Post Type
    $args = array(
    'label'               => __( 'products', 'twentythirteen' ),
    'description'         => __( 'product news and reviews', 'twentythirteen' ),
    'labels'              => $labels,
    // Features this CPT supports in Post Editor
    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields','tags' ),
    // You can associate this CPT with a taxonomy or custom taxonomy.
    'taxonomies'          => array( 'genres' ),
    /* A hierarchical CPT is like Pages and can have
    * Parent and child items. A non-hierarchical CPT
    * is like Posts.
    */
    'hierarchical'        => true,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
    );
    // Registering your Custom Post Type
    register_post_type( 'products', $args );
    }
    /* Hook into the 'init' action so that the function
    * Containing our post type registration is not
    * unnecessarily executed.
    */
    register_post_type( 'products' , $args );
    register_taxonomy("categories", array("products"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => array( 'slug' => 'products', 'with_front'=> false )));
    add_action( 'init', 'custom_post_type', 0 );

و با استفاده از کد زیر میخوام مطالب بعضی از دسته های این پست سفارشی رو نمایش بده :

 

$cat_posts= new WP_Query(array( 'post_type'=>'products','post_status'=>'publish','order'=>'DESC','orderby'=>'ID','cat'=>'17','posts_per_page'=>'10')); 
if($cat_posts->have_posts()):
while($cat_posts->have_posts()): $cat_posts->the_post();?>
<?php the_title();?>
<?php endwhile; endif; wp_reset_query();

 

اما هرررررررررر کاری میکنم هیچ پستی رو نشون نمیده ! مشکل کجاس ؟

لینک به ارسال

سلام من کدتون رو چک کردم کار میکنه و نمایش میده

فقط اینجا

register_post_type( 'products' , $args );
    register_taxonomy("categories", array("products"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => array( 'slug' => 'products', 'with_front'=> false )));
    add_action( 'init', 'custom_post_type', 0 );

این خط رو پاک کنید دوبار تکرار شده

register_post_type( 'products' , $args );

بعد برای نمایش بر اساس custom_taxonomy از آموزش زیر استفاده کنید

https://wordpress.stackexchange.com/questions/84921/how-do-i-query-a-custom-post-type-with-a-custom-taxonomy

 

لینک به ارسال

مرسی از پاسخت عزیز ولی با این کدی که فرمودی تمام پست های اون پست سفارشی رو نشون میده ! یعنی یه دسته خاص رو نمیشه نشون داد

لینک به ارسال

من یه دسته بندی برای اون پست تایپ ایجاد کردم ، میخوام مطالب دسته ای خاص از اون پست تایپ رو نشون بدم

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...