PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Can you filter populate-posts to exclude categories?

  1. Desmond
    Member

    I have used the populate-posts method to pre-populate a drop-down field with Post titles. What I would like to do would be to exclude 1 of 9 categories from the drop-down. Specific advice on how to do this?

    Thanks!

    Posted 12 years ago on Monday June 18, 2012 | Permalink
  2. David Peralty

    What code are you using currently to do this? You will have to change how you pull posts to exclude categories you want excluded. I would have to see how you are grabbing posts first though to be able to help as there are multiple ways to grab post titles.

    Posted 12 years ago on Tuesday June 19, 2012 | Permalink
  3. Desmond
    Member

    This is the code that I am using. If you could help me with specific syntax, that would be much appreciated. I want to exclude a category called "Guides".

    http://www.pastie.org/4127190

    Posted 12 years ago on Thursday June 21, 2012 | Permalink
  4. David Peralty

    So if you look at the documentation on the get_posts function in WordPress, you will see that it includes options for excluding categories:
    http://codex.wordpress.org/Template_Tags/get_posts

    I think you have to do it by the category numbers, and it will take a list of comma separated values if memory serves me.

    Posted 12 years ago on Thursday June 21, 2012 | Permalink
  5. Desmond
    Member

    Here's what worked for me, using the category argument and placing a minus symbol in front of the category ID.

    $posts = get_posts('numberposts=-1&post_status=publish&category=-12,-1&orderby=title&order=ASC');

    Posted 12 years ago on Tuesday June 26, 2012 | Permalink
  6. David Peralty

    Glad you figured it out.

    Posted 12 years ago on Wednesday June 27, 2012 | Permalink

This topic has been resolved and has been closed to new replies.