Support » Plugin: Display Posts - Easy lists, grids, navigation, and more » Exclude pages, only include posts

  • Resolved bwooster47


    [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


    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


    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


    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


    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


    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:
    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


    To add categories to pages, simply add this to your theme’s functions.php file (or a 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:

    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.