Skip to content

Bug with sticky post filter, overwriting SQL for WP_Query

Home Forums PP2 Technical Issues Bug with sticky post filter, overwriting SQL for WP_Query

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by 2 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22847 Reply

    This is in reference to the hook addition to option_sticky_posts in line 17 in press-permit-core/query-interceptor-front_pp.php. Reproduced below

    add_filter( 'option_sticky_posts', array(&$this, 'flt_sticky_posts') );
    ...
    public function flt_sticky_posts( $post_ids ) {
    if ( $post_ids && ! pp_is_content_administrator() ) {
    global $wpdb;
    $clauses = array_fill_keys( array( 'distinct', 'join', 'groupby', 'orderby', 'limits' ), '' );
    $clauses['fields'] = 'ID';
    $clauses['where'] = "AND ID IN ('" . implode( "','", $post_ids ) . "')";
    $clauses = apply_filters( 'pp_posts_clauses', $clauses );
    $post_ids = $wpdb->get_col( "SELECT {$clauses['distinct']} ID FROM $wpdb->posts {$clauses['join']} WHERE 1=1 {$clauses['where']}" );
    }

    return $post_ids;
    }

    On our site we identified an issue when there is no sticky post assigned and a user is not logged in with this ignoring posts_per_page WP_Query param for sticky posts and instead returning 30 posts by modifying the query directly. This was causing way too many posts to display on our homepage. You can see it as non-logged in user here: http://test-city-of-woburn.pantheonsite.io/

    When we are logged in, it’s important to note that we see the correct amount of items (which is supposed to be 4) and as soon as PP Core is deactivated the same is achieved. Also, as soon as I comment out the hook on like 17 (when PP Core is active) as referenced above, it also solves the problem.

    Here is the call to WP_Query that is being broken by the hook:

    $sticky = new \WP_Query( array(
    'post__in' => get_option('sticky_posts'),
    'ignore_sticky_posts' => true,
    'post_status' => 'publish',
    'post_type' => 'post',
    'posts_per_page' => 4,
    'suppress_filters' => true
    ) );

    I am happy to provide more information if necessary.

    #22852 Reply

    [ login required ]

    #22862 Reply

    [ login required ]

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Registered members have full access to Pro support forums here.

Feel free to log in or purchase a support key.