Last active
August 29, 2015 14:01
-
-
Save diegoliv/8b14884b8de2fb1d9804 to your computer and use it in GitHub Desktop.
Filtrando página de listagem de taxonomias usando pre_get_posts e post type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// registering the taxonomy "class-formation" | |
function theme_register_taxonomy(){ | |
$labels = apply_filters( 'tax_class_formation_labels' ,array( | |
'name' => _x( 'Formações Acadêmicas', 'Taxonomy General Name', 'theme_slug' ), | |
'singular_name' => _x( 'Formação Acadêmica', 'Taxonomy Singular Name', 'theme_slug' ), | |
'menu_name' => __( 'Formações', 'theme_slug' ), | |
'all_items' => __( 'Todos as Formações', 'theme_slug' ), | |
'parent_item' => __( 'Formação Pai', 'theme_slug' ), | |
'parent_item_colon' => __( 'Formação Pai:', 'theme_slug' ), | |
'new_item_name' => __( 'Novo nome de Formação', 'theme_slug' ), | |
'add_new_item' => __( 'Adicionar nova Formação', 'theme_slug' ), | |
'edit_item' => __( 'Editar Formação', 'theme_slug' ), | |
'update_item' => __( 'Atualizar Formação', 'theme_slug' ), | |
'separate_items_with_commas' => __( 'Separe formações acadêmicas com vírgulas', 'theme_slug' ), | |
'search_items' => __( 'Pesquisar formações', 'theme_slug' ), | |
'add_or_remove_items' => __( 'Adiciona ou remova formações', 'theme_slug' ), | |
'choose_from_most_used' => __( 'Escolha entre as formações mais usadas', 'theme_slug' ), | |
) ); | |
$rewrite = array( | |
'slug' => apply_filters( 'tax_class_formation_slug', _x( 'formacao-academica', 'Taxonomy Slug', 'theme_slug' ) ), | |
'with_front' => true, | |
'hierarchical' => false, | |
); | |
$args = apply_filters( 'tax_class_formation_args', array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => false, | |
'rewrite' => $rewrite, | |
) ); | |
register_taxonomy( 'class-formation', array( 'theme-courses', 'product' ), $args ); | |
} | |
add_action( 'init', 'theme_register_taxonomy' ); | |
// filtering the archive taxonomy page to get posts with "theme-courses" CPT | |
add_action( 'pre_get_posts', 'filter_tax_archive', 1 ); | |
function filter_tax_archive( $query ) { | |
if ( is_admin() || ! $query->is_main_query() ) | |
return; | |
if ( $query->is_main_query() && $query->is_tax( 'class-formation' ) ) { | |
$query->set( 'post_type', array( 'theme-courses' ) ); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment