Title: Exclude pages, only include posts
Last modified: July 29, 2017

---

# Exclude pages, only include posts

 *  Resolved [bwooster47](https://wordpress.org/support/users/bwooster47/)
 * (@bwooster47)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/)
 * `[display-posts category="MyCategory" post_type="post" exclude_current="true"
   posts_per_page="20"]`
 * does not work for me, not sure what is going on. The above displays both Pages
   and Posts in the list, any tips on how to debug this?
 * I’ve the above shortcode in a page.
 * Essentially, I only want the items listed in WordPress Posts dashboard menu and
   not from the Pages dashboard home menu.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [bwooster47](https://wordpress.org/support/users/bwooster47/)
 * (@bwooster47)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9368721)
 * OK, something very strange is going on, I added debug code to print the SQL statements.
 * For this:
    `[display-posts category="myslug" post_type="post" exclude_current
   ="true" offset="3" posts_per_page="4"]`
 * I see this SQL, which is clearly not what the code above asks for – the SQL is
   looking for both (page, post) instead of just (post).
 * Anyone have any tips on what to look at next?
 *     ```
       SELECT SQL_CALC_FOUND_ROWS  wp1_posts.ID FROM wp1_posts  LEFT JOIN wp1_term_relationships ON (wp1_posts.ID = wp1_term_relationships.object_id) WHERE 1=1  AND wp1_posts.ID NOT IN (7) AND ( 
         wp1_term_relationships.term_taxonomy_id IN (3)
       ) AND wp1_posts.post_type IN ('post', 'page') AND ((wp1_posts.post_status = 'publish')) GROUP BY wp1_posts.ID ORDER BY wp1_posts.post_date DESC LIMIT 3, 4
       ```
   
 *  Thread Starter [bwooster47](https://wordpress.org/support/users/bwooster47/)
 * (@bwooster47)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9368729)
 * Oh, and if it matters, I’m using the shortcode on a page.
    I.e., on a post_type
   of page, I need to display a list of the posts (and not pages) with a particular
   category.
 *  Thread Starter [bwooster47](https://wordpress.org/support/users/bwooster47/)
 * (@bwooster47)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9368837)
 * OK, the problem is with WP_Query
 * I can’t find this in the docs, but looks like if category=something is used, 
   it then changes the passed in args post_type to always include page too.
 * Or at least it is doing that for my setup.
 *  Plugin Author [Bill Erickson](https://wordpress.org/support/users/billerickson/)
 * (@billerickson)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9368917)
 * It sounds like your theme or a plugin has modified WP Query. I recommend you 
   try switching to the default WP theme and disabling all plugins except Display
   Posts Shortcode to confirm.
 * If it works with all plugins disabled, enable them one-by-one to determine the
   culprit. If it works with all plugins enabled, try switching back to your theme
   to confirm the issue is with your theme.
 * Once you know the source, you can dig into the code to find the specific issue,
   or contact the theme/plugin author.
 *  Thread Starter [bwooster47](https://wordpress.org/support/users/bwooster47/)
 * (@bwooster47)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9369664)
 * Thanks a lot, that helped find the bug.
 * My site uses a plugin to add categories to pages, and disabling that plugin makes
   display-posts shortcode work correctly.
    I’ll add a issue to that plugin’s support
   forum.
 * This plugin breaks WP_Query – it is very old it seems:
    [https://plugins.trac.wordpress.org/browser/add-category-to-pages/](https://plugins.trac.wordpress.org/browser/add-category-to-pages/)
   Add Categories to Pages. Easily add Categories and Tags to Pages. Simply Activate
   and visit the Page Edit SCreen. Version 1.0 | By a.ankit
 *  Plugin Author [Bill Erickson](https://wordpress.org/support/users/billerickson/)
 * (@billerickson)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9370421)
 * To add categories to pages, simply add this to your theme’s functions.php file(
   or a [Core Functionality plugin](https://www.billerickson.net/core-functionality-plugin/)).
 * `register_taxonomy_for_object_type( 'category', 'page' );`
 * The problem with that plugin is it modifies any WP query that includes a category
   or tag parameter to also query both ‘post’ and ‘page’ post types. A better approach
   would be to only change the query when it’s (a) the main query, and (b) on a 
   category or taxonomy archive page. Like this: [https://gist.github.com/billerickson/2aad7c960adbd68328c7f6b4351c354f](https://gist.github.com/billerickson/2aad7c960adbd68328c7f6b4351c354f)
 *  [karencho777](https://wordpress.org/support/users/karencho777/)
 * (@karencho777)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9422187)
 * Hello can you tell is there possible to display posts with “search keyword” not
   a tag!!! i need to plugin search whole content for example on keyword “John Rooney”,
   in posts there is no such a tag,but in content is,so it is possible?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Exclude pages, only include posts’ is closed to new replies.

 * ![](https://ps.w.org/display-posts-shortcode/assets/icon-256x256.jpg?rev=2940963)
 * [Display Posts - Easy lists, grids, navigation, and more](https://wordpress.org/plugins/display-posts-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/display-posts-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/display-posts-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/display-posts-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/display-posts-shortcode/reviews/)

 * 7 replies
 * 3 participants
 * Last reply from: [karencho777](https://wordpress.org/support/users/karencho777/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/exclude-pages-only-include-posts/#post-9422187)
 * Status: resolved