WordPress.org

Support

Support » Plugins and Hacks » [Resolved] the_posts() and get_pages() filters are totally broken

[Resolved] the_posts() and get_pages() filters are totally broken

  • the_posts and get_pages should be two filters to let you manipulate array that contains list of posts/pages, remove or change some items and return it back, at least according to this page:
    http://wphooks.flatearth.org/hooks/the_posts/

    However if you just try this very short code:
    //add_filter(‘the_posts’, ‘posts_pages_list’);
    add_filter(‘get_pages’, ‘posts_pages_list’);

    function posts_pages_list($posts) {

    if (!empty($posts))
    unset($posts[0]);

    return $posts;
    }

    you have two broken behaviors depending on which line you uncomment:

    1) with only the_posts filter you have a loop in manage pages that continue to draw pages and you have also two sql errors:

    SELECT post_id, category_id FROM wp_post2cat WHERE post_id IN (,8,7,9,10,11,12)

    SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN(,8,7,9,10,11,12) ORDER BY post_id, meta_key

    you have two very similar sql errors also in manage posts

    2) with only get_pages filter the site shows only a blank page and trying to print_r the array you can see that is magically truncated in the middle!!!

    What’s wrong??? Bug?

    Help me please

    thanx
    Marco

Viewing 2 replies - 1 through 2 (of 2 total)
  • probably I have understood, unset cannot be done because the first element of the array become [1] and probably wordpress is hardcoded to start from 0… Will try to change that.

    yes the problem is exactly this, should be used array_splice instead of unset, wordpress start from element number [0] hardcoded and no holes should be left in the array.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] the_posts() and get_pages() filters are totally broken’ is closed to new replies.