Support » Plugin: Sticky Posts - Switch » 502 Bad Gateway or Maximum function nesting level error in CPT archive page

  • Resolved Elvis Morales

    (@elvismdev)



    Hi there,

    After installing the plugin and enabling it to work in one of my custom post types, when I go to the archive page for the post type (e.g. /solutions) it throws a white page giving a “502 Bad Gateway” error.

    If I have xdebug enabled it throws a different error like this:

    Fatal error: Maximum function nesting level of '256' reached, aborting! in /wp-includes/cache.php on line 699

    Unchecking the “Show” checkbox for “Post Type Archive” in the plugin settings brings back to work as expected again the archive page. But then I don’t get the desired result where I want in the Archive page the sticky posts to show first on the list.

    I’m trying to use this plugin in a WordPress 5.0.1 installation if that helps.

Viewing 5 replies - 1 through 5 (of 5 total)
  • For more context, this happens when there is more than 1 custom post type selected to support sticky posts from the plugin options and they have some posts marked as sticky.

    Essentially, if the option sticky_posts has multiple post ID’s stored and they are from different post types together, when we are loading the archive page for just one of this post types, it breaks into the Maximum function nesting level error exactly when trying to do this query with get_posts(): https://plugins.trac.wordpress.org/browser/sticky-posts-switch/trunk/sticky-posts-switch.php#L583

    Any update on this issue?

    Thanks,

    Plugin Author Markus Froehlich

    (@markusfroehlich)

    Hello Elvis.

    Can you please simply add this code on the line 583.

    remove_filter('the_posts', array($this, 'the_posts'), 1, 2);
    $stickies = get_posts( array(
       'post__in'      => $sticky_posts,
       'post_type'     => $wp_query->query_vars['post_type'],
       'post_status'   => 'publish',
       'nopaging'      => true
    ) );
    add_filter('the_posts', array($this, 'the_posts'), 1, 2);

    Thank you and best regards
    Markus

    Elvis Morales

    (@elvismdev)

    @markusfroehlich That fixed it! Will you be applying this in the next plugin update?

    Need to make sure the site won’t lose this fix if the plugin gets updated.

    Thanks!

    Plugin Author Markus Froehlich

    (@markusfroehlich)

    Update is out now.
    Thank you for the bug report 🙂

    Best regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.