logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$8
Custom Post Query

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) {
$query->set('cat',''.$exclude.'');
}
return $query;
}
add_filter('pre_get_posts','wploop_exclude');



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.

This question has been answered.

WP Answers | 01/26/11 at 12:48pm Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/26/11
    12:56pm
    Dan | gteh says:

    have you tried adding

    wp_reset_query(); 


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

    http://codex.wordpress.org/Function_Reference/wp_reset_query

    Previous versions of this answer: 01/26/11 at 12:56pm

    • 01/26/11 1:02pm

      WP Answers says:

      Thanks for your response.

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

  • avatar
    Last edited:
    01/26/11
    1:03pm
    Gabriel Reguly says:

    Hi,

    Or have you tried to use

    remove_filter('pre_get_posts','wploop_exclude');


    at your particular page template?

    Regards,
    Gabriel Reguly

    • 01/26/11 1:03pm

      WP Answers says:

      Thank you!

      Works like a charm.

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

      Have a great day.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.