Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP WordPress Filter/Exclude Posts Category From Displaying In A Specific Page

WordPress Filter/Exclude Posts Category From Displaying In A Specific Page

This PHP is how to exclude categories of posts from displaying in a specific page. Please place this PHP code below in functions.php of your theme directory to cause your page to display posts only from some categories.

PHP – Filter Posts Category Of A Page In WordPress

For example we want to display only post categories with ID: 62,51,4 and 52 in a page has ID 118.

function ops_exclude_category( $query ) {
 
    if ( $query->queried_object->ID == 118)
    {
        $query->set( 'cat', '62,51,4,52' );
    }
}
add_action( 'pre_get_posts', 'ops_exclude_category' );

function ops_exclude_category( $query ) { if ( $query->queried_object->ID == 118) { $query->set( 'cat', '62,51,4,52' ); } } add_action( 'pre_get_posts', 'ops_exclude_category' );

In order to get more examples and have a deeper understand, please go to WordPress Plugin API/Action Reference/pre get posts

Sep 10, 2014Hoan Huynh
window.location.href target _blankAsp.net Gridview Simple Example
You Might Also Like:
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • How To Track Website With Multiple Google Analytisc Accounts
  • Get WordPress Most Popular Posts By Total Comments
  • WordPress Check If Post Is In Category
  • WordPress Get Recent Posts And Recent Comments
  • Delete WordPress Revision Posts, Its Relationships And Meta Data
  • Create Count Down Download Page With JavaScript
  • Show Error Message On WordPress Custom Login Template Page
  • Create Custom Update Profile Page For WordPress Users
  • Delete Bulk Draft And Trash WordPress Posts Includes All Tags, Comments, Meta Fields And Terms Associated
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

7 years ago PHPadd_action, pre_get_posts, queried_object, query_vars, Wordpress214
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,451 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,829 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,646 views
JQuery Allow only numeric characters or only alphabet characters in textbox
14,984 views
C# Read Json From URL And Parse/Deserialize Json
11,710 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development