• Skip to main content

Victor Font Consulting Group, LLC

Digital Business Strategists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Computers and Internet / Programming / WordPress / Genesis / Use query_args to Filter WordPress Posts in Genesis

Use query_args to Filter WordPress Posts in Genesis

By Victor M. Font Jr.
July 22, 201421 Comments

Circular Polarizing FilterThis tutorial answers the frequently asked question, "How do I filter blog posts to include or exclude specific categories on a Genesis Framework powered site?"

WordPress provides a very simple way to do this by using its built-in query_args attribute to apply a filter the WP_Query function, one of the most powerful features of WordPress. WP_Query determines what content displays on a page. Once you know how to use this built-in functionality, you’ll want to use it often to fit your specific needs. Using it to filter posts does not require any additional plugins, custom post types or PHP coding. Examples of what you can do by interacting with WP_Query include, but are not limited to:

  • Exclude posts from Category X on the homepage
  • Change the number of posts displayed per page for a specific post type
  • Filter which posts are shown and their display order based on postmeta
  • Execute a separate query for different content inside your page

For this tutorial, we are focusing simply on filtering posts displayed on a blog page. It may sound a little complex as you read through it, but the entire process takes less than a minute to complete if you follow the steps in order. It's that simple. The first step is finding the ID number for the category or categories you want to include or exclude on the page display.

Find the Category ID

When you setup a blog page in WordPress, the default behavior is to display all posts regardless of category. Sometimes it's useful to filter the blog page so only specific categories display. To filter for specific categories, you need to know the category ID number. WordPress assigns an internal ID number to every data element that you create that's stored in its data tables.

Navigate to Posts/Categories in the WordPress Admin area.

WordPress Categories Page

Notice that the category ID does not show up on this screen. To find the ID, hover your mouse over the category name on the right:

Get the WordPress Category ID

As I hover the mouse pointer over the category name, the URL for that category's page displays in the lower left of my browser window. The query string contains the following text: "tag_ID=3." The number referenced by tag_ID is the ID number of that particular category. Each category will have a different number. To filter your blog posts, jot down the category number(s) that you want to include or exclude. We'll be using them in the next step.

As an alternative, there is a plugin called Reveal IDs that I use on every WordPress install. WordPress versions prior to 2.5 displayed the data element IDs on the admin pages. For some reason, the WordPress developers removed this feature in version 2.5. The Reveal IDs plugin restores the feature by adding the ID column to the admin page display.

Reveal IDs plugin display

Filtering Your Posts

Now that the preliminaries are done, we can get to the main point of this tutorial—filtering your posts. I'm going to assume that you know how to setup a blog page in WordPress. You create a page and choose the blog template. Right? Open your blog page in the page editor and scroll down to the custom fields meta box:

Create Custom Fields in WordPress

If you don't see the custom fields meta box on your editing page, scroll up to the top and click screen options. Make sure the Custom Fields checkbox is checked. Close the screen options and scroll back down to the custom fields meta box.

Activate WordPress Custom Fields

Follow these steps:

  1. Click the Enter New link
  2. Enter "query_args" without the quotes into the text field above the link
  3. Click into the value field and enter "cat=3" without the quotes to include only category 3 posts on the blog page. If excluding the category, insert a minus sign before the category number (cat=-3).
  4. Click the Add Custom Field button
  5. Save the page
  6. View the blog page to test your results

You can also use this same technique to include or exclude more than one category of post. To include multiple categories, use cat=1,2,3 in the values field. Likewise, to exclude more than one category use cat=-1,-2,-3.

I use this technique on my publishing business website to filter posts for books, authors and marketing tips. Each category has its own blog page filtered to display posts only for that category.

  • 4shares
  • Facebook0
  • Twitter0
  • Pinterest2
  • LinkedIn2
  • Print
  • SMS0

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. Doug

    April 22, 2017 at 10:50 am

    Great tutorial – how do I make it so that the blog posts are just a brief sample of each like on this page? I want to display just the headline and first paragraph or so – bonus would be to add the featured image:

    http://uacnet.org/10984-2/

    Reply
    • Victor M. Font Jr.

      April 25, 2017 at 8:37 am

      Make your adjustment on the Genesis/Theme Settings page, Content Archives section.

      Reply
  2. Greg

    August 27, 2016 at 10:34 pm

    this seems to work in the “blog” section of the forum, but I’m looking to create a separate section for posts.

    So I’d like my “video” posts to be in the “Resource-Video” page, but I’d like my “how-to” post to be in the “Blog” page, and the “great articles” post to be seen in “Resources-Articles” page. The “query_args” doesn’t show the posts (in “Video” or “Articles”) as they are all appearing under “Blog” page.

    Tried the same with page to page and the “post=#” doesn’t work.

    Basically, click “resources” and all the child pages should appear on the page, and click the child page “video” and all the ‘video’ posts appear. Hope that makes sense.

    Reply
    • Victor M. Font Jr.

      August 28, 2016 at 8:30 am

      Greg,

      The query_args feature is for themes built on the Genesis Framework only. It won’t work for other themes. You’re alternative is to use a category link on your menu. This is a standard WordPress feature and works across all themes.

      Reply
  3. Andrea Bergareche

    June 12, 2016 at 2:30 am

    Hi, I tried to add category blog pages to my genesis blog but I can write query_args in the text field above the link. I can not writ in the text field, I can only select an option and query_args is not in the list.

    I don´t know how to solve it. I can´t add a screen capture to show you what appear in the list that appear in the text field above the add custom field link but query_args is not in the list…

    If you can help me…
    Thanks!

    Reply
    • Victor M. Font Jr.

      June 12, 2016 at 6:54 am

      I’m not sure what to tell you Andrea, but if you clicked the Enter New link, the drop down should go completely away and be replaced with a text field. If you cannot type anything in that text field, you are most likely experiencing a plugin conflict.

      Reply
      • Andrea Bergareche

        June 12, 2016 at 12:58 pm

        Victor, thanks for your fast answer.
        I desactivated all my plugins and I still have the same problem… I can not write what I like in the text field, I only can choose one of the options that appear on the list and query_args is not in the list…

        Do you have any idea about how to solve it?
        Thanks!

        Reply
        • Victor M. Font Jr.

          June 12, 2016 at 3:26 pm

          Andrea, please use the contact form on this site and send me your admin login credentials. I’m happy to take a look.

          Reply
  4. keith higginbotham

    April 7, 2016 at 10:01 pm

    I’m trying the same thing with a Genesis child theme, but don’t get the pagination unless I have that site set as the “blog” page for the entire site. Any idea what I’m doing wrong? I’m using your same technique.

    Thank you

    Reply
    • Victor M. Font Jr.

      April 9, 2016 at 8:26 am

      With Genesis themes, you never have to set the blog page for the entire site. Make certain you have the pagination you want selected in Genesis Setting Content Archives and you have the number of posts per page set in the Blog Page Template area. If pagination still doesn’t work, check your theme’s functions.php file or page-blog template (if it has one) to make sure the developer didn’t turn the feature off. The last thing, make sure you have enough posts in the filtered category to trigger the pagination. It won’t display unless you have a greater number of posts than the number of posts per page set in the Blog Page Template area.

      If none of this works, you need to start troubleshooting for a plugin conflict.

      Reply
  5. Haider

    September 22, 2015 at 9:25 am

    Hi Victor,

    How do I include multiple categories using this feature?

    For example: Cat ID 6 AND Cat ID 14

    Thanks.

    Reply
    • Victor M. Font Jr.

      September 22, 2015 at 9:32 am

      Hello Haider,

      To include multiple categories, use cat=1,2,3 in the values field.

      Victor

      Reply
      • Haider

        September 22, 2015 at 12:03 pm

        Hi Victor,

        Thanks for the quick response.

        cat=1,2,3 is for an OR relationship – i.e. Cat 1 or Cat 2 or Cat 3

        But, I need something for an AND relationship – i.e. Cat 1 and Cat 2 and Cat 3

        Any help would be appreciated.

        Thanks!

        Reply
        • Haider

          September 22, 2015 at 12:11 pm

          Hi Victor,

          No worries, I’ve figured it out:
          category__and[]=3&category__and[]=7

          Thanks anyway!

          Reply
          • Victor M. Font Jr.

            September 22, 2015 at 12:31 pm

            Glad you figured it out!

  6. Rose

    February 17, 2015 at 8:59 pm

    Hello-
    I’ve been following YouTube tutorials and reading sites online. I’ve been unable to link any posts to pages or have posts appear under pages and I was wondering if you had any advice as to why/how this query_args would not work for a page. I’ve done everything you’ve said and followed videos describing the same thing yet nothing comes up. All the pages are blank. Do you think this is a problem with CSS for the theme we’ve chosen?
    I would be very appreciative of any advice.
    Thank you,

    Reply
    • Victor M. Font Jr.

      February 17, 2015 at 10:29 pm

      Hello Rose,

      This tutorial applies to the Genesis Framework. Some theme developers provide other methods for hooking into the wp-query. This is for the Genesis Framework and all Genesis child themes only. Whatever theme you are using should have come with a blog template. Make sure you’ve selected the correct template for the page on which you want to display your posts.

      Reply
  7. Adrian Taciulescu

    December 15, 2014 at 2:40 pm

    Hm … maybe this is a feature of the Genesis framework? I’ve been trying a lot, even with non-existing cat-id’s, and the result does not change at all.

    Reply
    • Victor M. Font Jr.

      December 16, 2014 at 12:59 am

      You might be right!

      Reply
  8. Adrian Taciulescu

    December 15, 2014 at 10:57 am

    Hi Victor,

    Excellent tutorial, but it does not work on my site. Which WordPress Version do you use?

    Best

    Adrian

    Reply
    • Victor M. Font Jr.

      December 15, 2014 at 11:01 am

      Hi Adrian,

      I’m on the current version (4.01) and it works just fine. I’ve been using this on every version since 3.5. I can take a look if you’d like.

      Reply

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2022 Victor M. Font Jr.

Return to top of page
Posting....
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.OkNoCookie policy