WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_posts() and get_pages() filters are totally broken (3 posts)

  1. Marco Cimmino
    Member
    Posted 7 years ago #

    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

  2. Marco Cimmino
    Member
    Posted 7 years ago #

    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.

  3. Marco Cimmino
    Member
    Posted 7 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic