WordPress.org

Forums

[resolved] posts_where and gallery problems. (2 posts)

  1. OZtwo
    Member
    Posted 6 years ago #

    I'm having this problems with the below code:

    add_filter('posts_where', 'archive_where' );
    .
    .
    .
    function archive_where( $where ) {
    if (is_category()) {
    $varWhere = $_SESSION['ArchiveYear'];
    if ( intval($varWhere) <> 0 )
    $where .= " AND YEAR(post_date) = $varWhere";
    }
    return $where;
    }

    The filter works as I would like, but I found that when using the plugin, it breaks the gallery and some posts will not show the images in the gallery. I'm guessing that gallery is using the same query as defined above and can't find the needed information due to the date. Anyone know an answer to this problem?

  2. OZtwo
    Member
    Posted 6 years ago #

    Found the problem which as well could be a small bug that I hope was addressed with 2.7. Seems the action filter 'posts_where' is used both with posts and images being called for both. To fix the problem, for now, created a global var counter and have the function below work only at the value of 0.

    function archive_where( $where ) {
    global $arcWhere;
    if (is_category()) {
    $_SESSION['SavedWhere'] = $where;
    $varWhere = $_SESSION['ArchiveYear'];
    if ( intval($varWhere) <> 0 && intval($arcWhere) == 0 ) {
    $where .= " AND YEAR(wp_posts.post_date)='$varWhere'";
    }
    }
    $arcWhere++;
    return $where;

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags