即时通讯使用WordPress的3.8.1,想显示5个相关的投资组合,但我不知道如何查询。
我注册投资组合的代码是

add_action('init', 'portfolio_register');


function portfolio_register() {

$labels = array(
    'name' => _x('Portfolio', 'post type general name', "swiftframework"),
    'singular_name' => _x('Portfolio Item', 'post type singular name', "swiftframework"),
    'add_new' => _x('Add New', 'portfolio item', "swiftframework"),
    'add_new_item' => __('Add New Portfolio Item', "swiftframework"),
    'edit_item' => __('Edit Portfolio Item', "swiftframework"),
    'new_item' => __('New Portfolio Item', "swiftframework"),
    'view_item' => __('View Portfolio Item', "swiftframework"),
    'search_items' => __('Search Portfolio', "swiftframework"),
    'not_found' =>  __('No portfolio items have been added yet', "swiftframework"),
    'not_found_in_trash' => __('Nothing found in Trash', "swiftframework"),
    'parent_item_colon' => ''
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => false,
    'menu_icon' => 'dashicons-format-image',
    'rewrite' => false,
    'supports' => array('title', 'editor', 'thumbnail'),
    'has_archive' => true,
    'taxonomies' => array('portfolio-category')
   );

register_post_type( 'portfolio' , $args );


}

最佳答案

终于我找到了答案

$args=array(
              'tag__in' => $tag_ids,
              'post__not_in' => array($post->ID),
              'showposts'=>3,  // Number of related posts that will be shown.
              'post_type'=> 'portfolio'
              );

              $my_query = new wp_query($args);


最好

10-07 14:01