Support » Plugin: Recent Posts Widget Extended » [New Feature] Excluding currently displayed posts

  • I am working on a site where the client doesn’t want the widget list of articles to show any articles currently displayed in the page’s main loop, or the post that is currently displayed to be shown in the listing. To comply with this I’m needing to hack the module to add the functionality. To whom would I send this hack for future inclusion, since I can see it being useful elsewhere (also, I don’t want to reapply the changes any time an update is made).

    https://wordpress.org/plugins/recent-posts-widget-extended/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter AkiTendo

    (@akitendo)

    And I have it completed but need to know who to send it to.

    Plugin Author Ga Satrya

    (@satrya)

    You can add custom parameter to the rpwe_default_query_arguments filter. Just add exclude => get_the_ID() to the filter.

    Thread Starter AkiTendo

    (@akitendo)

    Not sufficient – on the homepage and archive pages there will be more than one ID in the main flow.

    I actually needed to add two things – one mentioned above – the other was to lock the category to match those of the currently displayed post. Both of these where implemented as checkboxes in the form.

    @akitendo: I need to apply the same, but my knowledge in coding is practically none. Do you have a recipe? Can it work if I add it to my child-theme?

    @akitendo: This is much wanted!
    Both things I’m looking for. How could I get the ‘hack’ or @satrya could it be possible to get this functions included in the next plugin update?

    I am also hoping for this update (to exclude the currently displayed post or posts).

    Where exactly should I add exclude => get_the_ID() to the filter?

    Should it go somewhere to the below code?

    add_filter( 'rpwe_default_query_arguments', 'your_custom_function' );
    function your_custom_function( $args ) {
        $args['posts_per_page'] = 10; // Changing the number of posts to show.
        return $args;
    }

    And then that code to functions.php?

    I tried Satrya’s suggestion but I don’t know how to apply it correctly, and it was breaking the widget instead. So I asked here:
    http://stackoverflow.com/questions/27969574/exclude-current-post-from-recent-posts-widget

    AkiTendo’s solution sounds better though, if he can provide the hack and we could add it in a child-theme?

    @satrya: Why not add this option to the widget?

    I have only basic coding knowledge and compared to other plugins I find the configuration of this plugin highly confusing.

    Plugin Author Ga Satrya

    (@satrya)

    Hi,
    I’m sorry for late reply, I’m pretty busy to update this plugin but I’ll add this feature soon. For now, please try

    add_filter( 'rpwe_default_query_arguments', 'your_custom_function' );
    function your_custom_function( $args ) {
       global $post;
        $args['exclude'] = $post->ID;
        return $args;
    }

    Thank you for dropping by.

    I just tried your suggestion. The current post still shows in rpwe.

    I have this in my child-theme functions.php:

    add_filter( 'rpwe_default_query_arguments', 'rpwe_exclude_current_post' );
    function rpwe_exclude_current_post( $args ) {
       global $post;
        $args['exclude'] = $post->ID;
        return $args;
    }

    Am I missing something?

    I found a similar situation in a site from a similar plugin an tried the solution suggested there. It worked here. I have no idea if it can affect the results in any other undesired way, but at least it doesn’t display the current post in rpwe.

    Here’s what I applied:

    add_filter( 'rpwe_default_query_arguments', 'rpwe_exclude_current_post' );
    function rpwe_exclude_current_post( $args ) {
    if( is_singular() && !isset( $args['post__in'] ) )
    $args['post__not_in'] = array( get_the_ID() );
    return $args;
    }

    taken from this location

    Any feedback is very much appreciated, in case you try this or find a better solution.

    @patternreplicas thank you very much for posting that last code. It worked for me too.

    I have also added to the array the posts which I wanted to exclude and it worked: array( get_the_ID(),100,101 );

    I hope that it will not break our web sites once the plugin gets updated. But it seems to be working fine.

    Great that it is working for you too : )
    About “breaking the websites when the plugin gets updated”, all you have to do is create a child-theme and add these changes there instead of in your theme’s folder. It was one of the first things I did, it’s very easy and everyone in any forum post seems to be sure it’s the best way for not having trouble when plugins, or the theme itself, updates.

    http://codex.wordpress.org/Child_Themes

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[New Feature] Excluding currently displayed posts’ is closed to new replies.