$4
Excluding Categories
I have a custom wordpress theme with a custom admin panel. There is an area where a user can type in which categories they want to hide. (ie: -5,-6,-7)
I am trying to pull in this value that they set and exclude those categories from the blog.
I know logically how to do it, but I'm having a bit of trouble.
On the blog page, I have modified "the loop" to the code below. That is how I need the final output to look. the only difference is that I am storing my values into a variable so I need I'm going to need format the loop a bit differently.
<?php query_posts(cat='-5,-6,-7''); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Logically this is what I need to do but it's not written correctly. Any help is greatly appreciated.
<?php $excludefull = get_option('nt_exclude'); ?>
<?php query_posts(cat='$excludefull'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
WP Answers | 04/15/10 at 8:38pm
| Edit
(1) Possible Answers Submitted...
-

Last edited:
04/15/10
9:22pmLew Ayotte says:Is that the code you're using?
Chang query_posts to:
<?php query_posts('cat=' . $excludefull); ?>
Lew- 04/15/10 9:05pm
WP Answers says:Thank you for that but it didn't work.
Would I need to add a closing quote ' so that it reads like: cat='-7'
in the code above there is no closing quote.
The value the the variable returns looks like this: -7,-6
Thanks a lot for your help. - 04/15/10 9:07pm
Lew Ayotte says:$excludefull should be a string, so there is no need to quote it...
What displays when you do this:
<?php echo $excludefull; ?>
Lew - 04/15/10 9:10pm
WP Answers says:Ah, ok I understand.
Here's what displays: -7,-3 - 04/15/10 9:12pm
Lew Ayotte says:Hrm... that should work then... you're sure that the category IDs are 7 and 3?
What happens when you try this as a test?
<?php query_posts('cat=-7,-3'); ?>
Lew - 04/15/10 9:13pm
WP Answers says:Your Code was perfect.
i just wfound out whats causing the issue.
In my functions.[h[ file I had some code to help exclude categories from the archives widget.
Any chance you know how to modify this code from the functions.php file so that it excludes those same categories from widgets as well?
function exclude_category($query) {
if ( $query->is_home ) {
$query->set('cat', '-7,-3');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
- 04/15/10 9:20pm
Lew Ayotte says:It would probably depend on the widget and if the widget is part of WP Core... and if there are any action hooks for that widget.
- 04/15/10 9:05pm
This question has expired.
Current status of this question: Completed





