WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] not to include current ID (7 posts)

  1. mgrant
    Member
    Posted 2 years ago #

    display-posts-shortcode displays the current post in a list of posts which always included the current post. This didn't make sense to me, especially if you're trying to display a list of other posts with the same tag within a post. Perhaps there should be an arg like 'do_not_include_current_ID' or something like that. However, for now, adding this to display-posts-shortcode.php fixed my problem:

    // If Post IDs
    	if( $id ) {
    		$posts_in = explode( ',', $id );
    		$args['post__in'] = $posts_in;
    >	} else {
    >		$args['post__not_in'] = array(get_the_ID());
    >	}

    The idea was that if you didn't specify a particular ID, then it would exclude the current ID. The reasoning was because you can not specify both post__in and post__not_in in the same set of args.

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

  2. Bill Erickson
    Member
    Plugin Author

    Posted 1 year ago #

    Great idea, but it's best to use a filter rather than modifying the plugin. Here's how to do it: http://www.billerickson.net/code/display-posts-exclude-current-post/

  3. mgrant
    Member
    Posted 1 year ago #

    It's true that in general it's better to not modify a plugin. However, I'm really proposing this as a bug fix. As I said, the behavior as is doesn't make sense.

  4. Bill Erickson
    Member
    Plugin Author

    Posted 1 year ago #

    It's not a bug since the default behavior of the plugin is to not limit any specific posts. But if you do want it limited in the way you describe, you can use the filter as outlined in the code I provided.

  5. Kyle
    Member
    Posted 1 year ago #

    Hey Bill,

    2 questions:

    1) It seems, based on the thread above, that if I wanted to add some more exclusion functionality to your Display_Posts_Shortcode plugin, you would recommend that I use the filter you provided - right?

    2) I'm not sure I completely understand how to use the filter but here's a guess - I need to write custom, unsupported code to do the exclusions and then stick it in with your code calling your filter function. Is that right?

  6. Kyle
    Member
    Posted 1 year ago #

    Based on a one of your comments on a different thread, I infer that the answer to question #2 is to stick the filter code into the functions.php file, right?

    How would you feel if I forked the code and added my exclusion options? Would you pull those changes into the master?

  7. Bill Erickson
    Member
    Plugin Author

    Posted 1 year ago #

    You can include your changes in your theme's functions.php file, or write a separate plugin that uses the filters. That's what makes filters and hooks so great - you're able to easily extend a plugin's functionality without modifying the core.

    If you think the changes you've made are of use to most people, you can submit a pull request on Github or just post the code here and I can take a look.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic