Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Post Query WordPress


Hi There,

I've built some functionality into a custom theme that allows users to exclude certain categories from the blog, archives, search, RSS, etc. This function modifies the post query to exclude the categories that are predefines by the user. Everything is working as expected. I've added the code below to my functions file. (please note that the variable storing the categories holds a value that looks like this: -1,-2,-3,)

function wploop_exclude($query) {
$exclude = get_option('ka_blogexclude');
if ($query) {
return $query;

The Problem:
I have some more custom functionality that allows the user to choose a category to pull posts from, and it displays those posts in a nice jquery slider on one of the page templates. The issue I'm having is that the modified query above is also affecting this page template. Is there anyway to define another 'custom query' that will only be used in this particular page template? This new query should only pull posts from the defined category. I'm assuming it will look very similar to the query above, but will be grabbing a different value for the categories. I tried using the is_page_template function but didn't get the result I was after.

I greatly appreciate your help.

Answers (2)


Gabriel Reguly answers:


Or have you tried to use


at your particular page template?

Gabriel Reguly

WP Answers comments:

Thank you!

Works like a charm.

It's great learning about new Wordpress functions I've never used. ;)

Have a great day.


Dan | gteh answers:

have you tried adding

above the loop on the page where you do NOT want this function to be applied to?

WP Answers comments:

Thanks for your response.

Yes, I added the reset but it had no effect.