出于某种原因,我发现使用自定义分类法获取任何帖子都很困难。。。有人能解释我的愚蠢吗?
$args = array(
\'post_type\' => \'adverts\',
\'advert_tag\' => \'politics\' // Doesn\'t seem to work.
);
query_posts($args);
while ( have_posts() ) : the_post();
//Show Posts
endwhile;
分类声明:
add_action( \'init\', \'add_custom_taxonomy\', 0 );
function add_custom_taxonomy() {
register_taxonomy(\'advert_tag\', \'Adverts\',
array(
\'hierarchical\' => true,
\'labels\' => array(
\'name\' => _x( \'Advert Tags\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Advert Tag\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Advert Tags\' ),
\'all_items\' => __( \'All Advert Tags\' ),
\'parent_item\' => __( \'Parent Advert Tag\' ),
\'parent_item_colon\' => __( \'Parent Advert Tag:\' ),
\'edit_item\' => __( \'Edit Advert Tag\' ),
\'update_item\' => __( \'Update Advert Tag\' ),
\'add_new_item\' => __( \'Add New Advert Tag\' ),
\'new_item_name\' => __( \'New Advert Tag Name\' ),
\'menu_name\' => __( \'Advert Tags\' ),
),
\'rewrite\' => array(
\'slug\' => \'advert-tags\',
\'with_front\' => false,
\'hierarchical\' => true
),
);
}
自定义帖子类型声明:
add_action( \'init\', \'create_post_type\' );
function create_post_type() {
register_post_type( \'Adverts\',
array(
\'labels\' => array(
\'name\' => __( \'Adverts\' ),
\'singular_name\' => __( \'Advert\'),
\'add_new\' => __( \'Add New\' ),
\'add_new_item\' => __( \'Add a New Advert\' ),
\'edit\' => __( \'Edit\' ),
\'edit_item\' => __( \'Edit Advert\' ),
\'new_item\' => __( \'New Advert\' ),
\'view\' => __( \'View\' ),
\'view_item\' => __( \'View Advert\' ),
\'search_items\' => __( \'Search Adverts\' ),
\'not_found\' => __( \'No Adverts found\' ),
\'not_found_in_trash\' => __( \'No Adverts found in Trash\' ),
),
\'supports\' => array(
\'title\',
\'thumbnail\',
),
\'has_archive\' => true,
\'menu_position\' => 10,
\'public\' => true,
\'rewrite\' => array(
\'slug\' => \'adverts\'
),
\'taxonomies\' => array(\'advert_tag\')
)
);
}