WordPress.org

Make WordPress Core

Ticket #7155: calendar-sql-hook.patch

File calendar-sql-hook.patch, 2.6 KB (added by abelcheung, 10 years ago)

Adding a hook 'getcalendar_where'

  • general-template.php

    old new function get_calendar($initial = true) { 
    489489                }
    490490        }
    491491
     492        //filters
     493        $where = apply_filters('getcalendar_where', "WHERE post_type = 'post' AND post_status = 'publish'");
     494
    492495        ob_start();
    493496        // Quick check. If we have no posts at all, abort!
    494497        if ( !$posts ) {
    495                 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
     498                $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts $where ORDER BY post_date DESC LIMIT 1");
    496499                if ( !$gotsome )
    497500                        return;
    498501        }
    function get_calendar($initial = true) { 
    530533
    531534        // Get the next and previous month and year with at least one post
    532535        $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
    533                 FROM $wpdb->posts
    534                 WHERE post_date < '$thisyear-$thismonth-01'
    535                 AND post_type = 'post' AND post_status = 'publish'
     536                FROM $wpdb->posts $where
     537                AND post_date < '$thisyear-$thismonth-01'
    536538                        ORDER BY post_date DESC
    537539                        LIMIT 1");
    538540        $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
    539                 FROM $wpdb->posts
    540                 WHERE post_date >       '$thisyear-$thismonth-01'
     541                FROM $wpdb->posts $where
     542                AND post_date > '$thisyear-$thismonth-01'
    541543                AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
    542                 AND post_type = 'post' AND post_status = 'publish'
    543544                        ORDER   BY post_date ASC
    544545                        LIMIT 1");
    545546
    function get_calendar($initial = true) { 
    593594
    594595        // Get days with posts
    595596        $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    596                 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
     597                FROM $wpdb->posts $where
    597598                AND YEAR(post_date) = '$thisyear'
    598                 AND post_type = 'post' AND post_status = 'publish'
     599                AND MONTH(post_date) = '$thismonth'
    599600                AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
    600601        if ( $dayswithposts ) {
    601602                foreach ( $dayswithposts as $daywith ) {
    function get_calendar($initial = true) { 
    612613
    613614        $ak_titles_for_day = array();
    614615        $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
    615                 ."FROM $wpdb->posts "
    616                 ."WHERE YEAR(post_date) = '$thisyear' "
     616                ."FROM $wpdb->posts $where"
     617                ."AND YEAR(post_date) = '$thisyear' "
    617618                ."AND MONTH(post_date) = '$thismonth' "
    618619                ."AND post_date < '".current_time('mysql')."' "
    619                 ."AND post_type = 'post' AND post_status = 'publish'"
    620620        );
    621621        if ( $ak_post_titles ) {
    622622                foreach ( $ak_post_titles as $ak_post_title ) {