Reply To: Mashup with date filter

Home Forums MapPress Support Mashup with date filter Reply To: Mashup with date filter

#11245
BradSiegfried
Participant

    I think you’ll need to write some PHP since you want a date range calculated based on the current date.  When I need to write shortcodes, I keep them in a utility plugin so I don’t have to worry about theme changes.  You can learn a lot by looking at the plugins that other people have written.  See http://codex.wordpress.org/Writing_a_Plugin for some help getting started.

    You might do something along the lines of the code below to filter by date:

    global $my_datefrom, $my_dateto;

    // Create a new filtering function that will add our where clause to the query
    function my_filter_where($where = ”) {
    global $my_datefrom, $my_dateto;
    if ($my_datefrom) $where .= ” AND post_date >= ‘” . $my_datefrom;
    if ($my_dateto) $where .= “‘ AND post_date <= ‘” . $my_dateto . “‘”; else $where .= “‘”;
    return $where;
    }

    // [my_querymap my_datefrom=”2012-07-01″ my_dateto=”2012-12-02″ ]
    function my_querymap($atts, $content = null) {

    global $my_datefrom, $my_dateto;

    extract( shortcode_atts( array(
    ‘my_datefrom’ => date(‘Y-m-d’, strtotime(‘-30 days’)),
    ‘my_dateto’ => date(‘Y-m-d’),
    ), $atts ) );
    $result = “”;

    // Do the query to return desired posts for my_datefrom to my_dateto:
    $my_query_string = array(‘category_name’ => ‘my_categoryname’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘posts_per_page’ => ‘-1’);
    // Add a filter that will add our where clause to the query
    add_filter(‘posts_where’, ‘my_filter_where’);
    $my_query = new WP_Query( $my_query_string );
    $my_news = $my_query->get_posts();
    remove_filter(‘posts_where’, ‘my_filter_where’);

    … more code would go here to create the map from the query results …

     

    I hope that helps.  If not, maybe Chris can suggest an easier way to do what you want.

    Brad