• Having trouble with this plugin and Memberpress. Memberpress sent me this email:

    Hi Steve,

    Most likely the plugin is doing its own sub wp query, which causes a known bug with WordPress filters. Unfortunately the bug has been known about for 5 years by the WordPress developers but has yet to be addressed. You can read up on it here: https://core.trac.wordpress.org/ticket/17817

    The easiest work-around that I know of, which you can run by the authors of this recent posts plugin if you’d like, is to do something like this with the $wp_filter global. This should hopefully give them enough to work around this issue until WP gets around to implementing a proper fix.

    function my_shortcode_callback($atts, $content = '') {
        global $post;
        global $wp_filter;
    
        $original_filter = $wp_filter;
        $args            = array(//SOME ARGS HERE//);
        $original_post   = $post;
        $wp_query        = new WP_Query($args);
    
        ob_start();
    
        while($wp_query->have_posts()) {
          $wp_query->the_post();
    
          //Avoid infinite loop
          if($original_post->ID === $post->ID) {
            continue;
          }
    
          the_content();
        }
    
        // Reset the global query.
        wp_reset_query();
        wp_reset_postdata();
    
        $wp_filter = $original_filter; //Reset $wp_filter global to the way it was before we ran the sub-query
    
        return ob_get_clean();
    }
    add_shortcode('some-custom-loop', 'my_shortcode_callback');

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

The topic ‘sub wp query – error with Memberpress’ is closed to new replies.