• Skip to main content
  • Skip to primary sidebar

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

  • 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

Use query_args to Filter WordPress Posts in Genesis

July 22, 2014 By Victor M. Font Jr.

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

Filed Under: Genesis, How To, Tutorial, WordPress Tagged With: How To, Tutorial, WordPress

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.

Primary Sidebar

Shopping Cart

Books

  • Ultimate Guide to the SDLC front cover The Ultimate Guide to the SDLC
    Rated 5.00 out of 5
    $74.95
  • Winning With WordPress Basics 2nd Edition Winning With WordPress Basics 2nd Edition $19.95

Recent Articles

  • Protected: WordPress Database Modernization Blueprint
  • Social Media Management
  • Site Growth Automation
  • GDPR Compliance Monitoring
  • Digital Strategy Accelerator

Top 10 Article Categories

Best Practice Code Snippet Computers and Internet Genesis How To Leadership Programming Servant Leadership Tutorial WordPress

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