I am using this function to show my custom post type "portfolio" on archives / category / tag pages (Function .php):
function namespace_add_custom_types ($ query) {if (is_category ()} is_tag () & amp; empty ($ query- & gt; query_vars ['suppress_filters'] )) {$ Query-> Set ('post_type', array ('post', 'portfolio')); Return $ query; The problem is that for some reason this is missing my NAV menu. Here is the code for the NAV menu (header.php) Add_filter ('pre_get_posts',' namespace_add_custom_types' ' :
& lt ;? php wp_nav_menu (array ('theme_location' = & gt; 'primary', 'sort_column' = & gt; 'menu_order', 'menu_class' = & gt; Navi-Menu In WordPress nav menu nav_menu_item is posted post type, and as your function changes the post type for all queries, there too if (is_category () and $ query-> is_main_query (),) {// do stuff} PS: < Code> pre_get_posts is a action hook, so that you select add_filter : instead of add_action Add_action ('pre_get_post', 'namespace_and_play_type');
No comments:
Post a Comment