The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Wp_Query dates before xxxx-xx-xx (2 posts)

  1. dangayle
    Posted 6 years ago #

    I'm trying to create a loop of posts of the current author that are dated on or before the current page's published date.

    My query params:

    $query = array(
    		'posts_per_page' => 3, //number of results
    		'author' => $post->post_author, //only this author
    		'post__not_in' => array($post->ID), //NOT this post
    		'cat' => '513,517,1151,8690', //from this category
    		'post_type' => 'post', //only posts
    		'dated_before' => '2010-01-01' //DESIRED QUERY PARAMETER

    Here is the posts_where filter that I'm attempting to use:

    function dg_dated_before($where)
        global $wp_query;
        if ($wp_query->query_vars['dated_before']):
            $where = $where . " AND posts.post_date <= '". $wp_query->query_vars['dated_before'] . "' " ;
        return $where ;
    add_filter('posts_where', 'dg_dated_before') ;

    But obviously, it doesn't work, else I wouldn't post it here :(


  2. dangayle
    Posted 6 years ago #

    Probably shouldn't have skipped this part right after I defined $query:
    $queryObject = new WP_Query($query);

Topic Closed

This topic has been closed to new replies.

About this Topic