• Resolved mgrant

    (@mgrant)


    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/

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

    (@billerickson)

    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/

    Thread Starter mgrant

    (@mgrant)

    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.

    Plugin Author Bill Erickson

    (@billerickson)

    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.

    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?

    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?

    Plugin Author Bill Erickson

    (@billerickson)

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Display Posts Shortcode] not to include current ID’ is closed to new replies.