php - How to hide a custom Post Type Category using pre_get_posts -
My theme is a custom post type in my theme. Its categories are called project categories to log in to members I am trying to exclude a project category. My first question is, can I give project categories as a general post category reference?
This is a code that is not working yet. I've read through codex but I think I'm missing something
function exclude_category ($ query) {if (is_user_logged_in () and $ query- & gt; is_main_query ()) {$ Query- & gt; Set ('cat', '-94'); }} Add_action ('pre_get_posts', 'exclude_category');
There are custom post type classifications
# ------------------- - -------------------------------------------- # # of Classified Affiliate Portfolio for ----------------------------------------------- -- ---------------- # $ category_labels = array ('name' = & gt; __ ('project categories', NECTAR_THEME_NAME),' singular_name '= & gt; __ (' project ( "all project categories ', NECTAR_THEME_NAME),' parent_item '= & gt; __ (' parent 'project category', NECTAR_THEME_NAME), or 'edit_item' = & gt; __ ( 'edit project category', 'NECTAR_THEME_NAME'), 'Update_item' = & gt; __ ('Update Project Category ', NECTAR_THEME_NAME),' add_new_item '= & gt; __ (' Add new project category ', NECTAR_THEME_NAME),' menu_name '= & gt; __ (' Project Categories', NECTAR_THEME_NAME)); true, 'query_var' = & Array ("hierarchical" = & gt; correct, 'labels' = & gt; $ category_labels, 'show_ui' 'rewrite' => Array ("Portfolio"), array ("Portfolio"), array ("Portfolio"); 'Slug' = & gt; 'Project-type'))); $ Attributes_labels = array ( 'name' = & gt; __ ( 'Project Properties', NECTAR_THEME_NAME),' singular_name '= & gt; __ (' project featuring ', NECTAR_THEME_NAME),' search_items' = & gt; __ ( 'search Project Attributes ',' Edit_item '= & gt; __ (' Edit Project Properties '),' all_items '= & gt; __ (' All Project Attributes ', NECTAR_THEME_NAME),' parent_item '= & gt; __ (' parent project attribute ', NECTAR_THEME_NAME)', NECTAR_THEME_NAME), 'update_item' = & gt; __ ( 'update project Atitid', NECTAR_THEME_NAME), 'add_new_item' = & gt; __ ( 'Add new project featuring', NECTAR_THEME_NAME), 'new_item_name '= & Gt; __ (' new project attrib Duty ', NECTAR_THEME_NAME),' menu_name '= & gt; __ (' Project Properties', NECTAR_THEME_NAME)); True, 'query_var' = & gt; True, 'project-attributes', array ('portfolio'), array ('hierarchical' = & gt; right, 'labels' = & gt; $ attributes_labels, 'show_ui' 'rewrite' = & gt; array '= & Gt;' project-attributes')));
I have not received any error, but when I'm logged in, the category is not being excluded.
Any help would be greatly appreciated Thanks
Update:
I have also tried without luck for them
function exclude_category ($ Query) {if (is_user_logged_in ()) & amp; ; $ Query-> Is_main_query ()) {$ taxquery = array (array ('post_type' = & gt; portfolio ',' taxonomy '= & gt;' project-type ',' field '= & gt;' id 'rule' = & Gt; array (94), 'operator' = & gt; 'no')); $ Query- & gt; Set ('tax_coreia', $ taxquery); }} Add_action ('pre_get_posts', 'exclude_category');
and also
function exclude_category ($ query) {if_user_logged_in () & amp; $ Query- & gt; Is_main_query ()) {$ Taxquery = array (array ('post_type' = & gt; portfolio ',' taxonomy '= & gt;' project-type ',' field '= & gt;' slug ',' terms' = & Gt; 'preview' operator '= & gt;' no ')); $ Query- & gt; Set ('tax_coreia', $ taxquery); }} Add_action ('pre_get_posts', 'exclude_category');
Add logic to it.
function exclude_category ($ Query) {if_user_logged_in () & amp; $ Query- & gt; Is_main_query ()) {$ taxquery = array ('classification' = & gt; 'project-type', 'field' => id ',' word '= & gt; array (94),' operator '= & Gt; not in ''); $ Query- & gt; Set ('tax_coreia', $ taxquery); }} Add_action ('pre_get_posts', 'exclude_category');
Comments
Post a Comment