Support » Plugin: Display Posts Shortcode » [Plugin: Display Posts Shortcode] display posts from all categories

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Bill Erickson


    You must have a plugin interfering with the query. Have you tried disabling other plugins?

    [display-posts posts_per_page=”6″] will work assuming you don’t have a theme or plugin that’s poorly constructed and breaks other queries.

    I have pinpointed the problem: Sticky posts.

    Posts that are designated as sticky posts appear *in addition* to the number of posts_per_page requested.

    To see this in action, request, say, 3 posts, and make sticky a post that is not within the 3 most recent posts. You should see 4 posts, with the sticky in the first position.

    I fixed it by adding 'ignore_sticky_posts' => 1 to the below. This prevents stickies from showing at the top but will leave them showing in their natural order by date, if they happen to fall within the requested number of posts:

    // Set up initial query for post
    	$args = array(
    		'post_type' => $post_type,
    		'tag' => $tag,
    		'category_name' => $category,
    		'posts_per_page' => $posts_per_page,
    		'order' => $order,
    		'orderby' => $orderby,
    		'ignore_sticky_posts' => 1

    If you agree, perhaps you could update the plugin so I don’t have to hack it and babysit it?

    Plugin Author Bill Erickson


    I don’t think it’s necessary to modify the plugin and issue an update for this. If you are using sticky posts, this is the expected behavior.

    If you use them and don’t want them showing up in your shortcode’s listing, add this to your theme’s functions.php file or your core functionality plugin:

    function be_exclude_sticky_from_display_posts( $args ) {
    	$args['ignore_sticky_posts'] = 1;
    	return $args;
    add_filter( 'display_posts_shortcode_args', 'be_exclude_sticky_from_display_posts' );

    Hm, I guess you are right about that! Though it’s not the behavior I would expect — but that’s WP’s fault, not yours. Thank you for the filter!

    I just wanted to clarify, though, for others that may be following, that ignore_sticky_posts doesn’t actually ignore those posts (for the shortcode or anything else). It just relieves them of sticky duty.

    Instead of their busting out of chronological order to the top of the posts and appending themselves to the requested number of posts, they just wait their turn. That is to say, they act like regular posts.

    Personally, I find it odd that anyone would want their blog’s “read me” stickies to be stuck to the thing that might have led them to this plugin in the first place.

    Plugin Author Bill Erickson


    I completely agree, which is why I never recommend using sticky posts. It’s a relic of early versions of WordPress.

    If you want information at the top of your blog, add a widget area to your theme so you can manage it with a text widget.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Display Posts Shortcode] display posts from all categories’ is closed to new replies.