使用自定义分类法在自定义帖子类型中按类别ID发帖

时间:2015-07-02 10:46:04

标签: wordpress custom-post-type custom-taxonomy

请帮助我......这是我创建自定义帖子类型及其分类的脚本。它按类别ID成功创建了胸部提取问题。在我的类别中有3个帖子,但无法获得任何一个帖子。

用于创建代码:

function man_ourteam_custom_init() {
    $man_labels = array(
        'name' => 'Member',
        'singular_name' => 'ourteam',
        'add_new' => 'Add New',
        'add_new_item' => 'Add New Member',
        'edit_item' => 'Edit Member',
        'new_item' => 'New Member',
        'all_items' => 'All Member',
        'view_item' => 'View Member',
        'search_items' => 'Search Member',
        'not_found' => 'No Member found',
        'not_found_in_trash' => 'No Member found in Trash',
        'parent_item_colon' => '',
        'menu_name' => 'Our Team'
    );
    $man_args = array(
        'labels' => $man_labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'ourteam'),
        'capability_type' => 'post',
        'has_archive' => true,
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title', 'editor', 'thumbnail')     
    );
    register_post_type('ourteam', $man_args);

   register_taxonomy("member-category", array("ourteam"), array("hierarchical" => true, 'show_admin_column' => true,
        "label" => "Member Categories",
        "singular_label" => "Member Categories",
        "rewrite" => array('slug' => 'ourteam')));
}

add_action('init', 'man_ourteam_custom_init');

对于帖子获取代码:

我的类别ID为191,它有3个帖子。

$ourteam_category_check = '191';

            $niche_ourteam_args = array(
                'post_type' => 'ourteam',
                'cat'   => $ourteam_category_check,                 
                'orderby' => 'post_date',               
                'order' => 'DESC',
                'post_status' => 'publish',
                'meta_query' => array(
                    array(
                        'key' => '_thumbnail_id',
                        'compare' => 'EXISTS'
                    ),
                )
            );          

            $niche_ourteam = new WP_Query($niche_ourteam_args);

            while ($niche_ourteam->have_posts()) : $niche_ourteam->the_post();

                /*** My loop code ***/

            endwhile;

1 个答案:

答案 0 :(得分:2)

您需要添加' tax_query',而不是' cat' ..

declare
  l_ext_files_names varchar2(4000) := '&1';
  l_schema_name varchar2(4000) := '&2';
  l_table_name varchar2(4000) := l_schema_name||'.files_tbl';
  l_int_files_names varchar2(4000);
  c_file_name sys_refcursor;
begin
  open c_file_name for 'select file_names from '||l_table_name;
  loop
     fetch c_file_name into l_int_files_names;
     if (l_int_files_names <> l_ext_files_names) then
        insert into l_table_name (file_names, status)
        values (l_files_names, 'done');
     end if;
  end loop;
  close c_file_name;
end;