WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] display posts from all categories (7 posts)

  1. raskull
    Member
    Posted 2 years ago #

    How can I display posts from all categories, and the right number of them?

    [display-posts posts_per_page="6"] returns 8 instead of 6 posts. Same for this: [display-posts category="" posts_per_page="6"]

    How can I display posts from all categories, and all of them?

    [display-posts] returns less than all of them.

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. raskull
    Member
    Posted 2 years ago #

    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?

  4. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    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' );
  5. raskull
    Member
    Posted 2 years ago #

    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!

  6. raskull
    Member
    Posted 2 years ago #

    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.

  7. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic